V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Livid
V2EX  ›  Python

Python 代码中的未使用的 import 会有哪些负面影响呢?

  •  
  •   Livid · 2014-07-17 19:20:26 +08:00 via iPhone · 5143 次点击
    这是一个创建于 3582 天前的主题,其中的信息可能已经有所发展或是发生改变。
    10 条回复    2014-07-18 14:26:05 +08:00
    JohnDeng
        2
    JohnDeng  
       2014-07-17 19:29:35 +08:00
    编译的时候多一些无用指令。
    xingzhi
        3
    xingzhi  
       2014-07-17 22:17:19 +08:00
    如果被import的文件在函数体外还有执行语句或者有其它依赖的话,会带来不必要的麻烦。
    tonyluj
        4
    tonyluj  
       2014-07-17 22:38:17 +08:00
    所以在Go语言中,无效的import 会直接报错~~~
    siteshen
        5
    siteshen  
       2014-07-17 22:48:05 +08:00   ❤️ 1
    过不了flake8又能简单fix的东西都要fix。
    phuslu
        6
    phuslu  
       2014-07-17 23:07:01 +08:00   ❤️ 1
    坚决不能 import, 会增大内存占用。尤其是 virt 占用。
    clino
        7
    clino  
       2014-07-18 09:09:57 +08:00
    像ulipad就有提示未使用的import的功能,我觉得主要不好的地方还是内存占用吧
    xiaket
        8
    xiaket  
       2014-07-18 10:31:29 +08:00
    import不仅仅是占用内存. import一个模块的时候可能会执行过一些代码, 万一这些执行的代码会对整个程序运行有不良影响就挂了.
    zzcflying
        9
    zzcflying  
       2014-07-18 10:54:28 +08:00
    楼上说的好可怕。好怕怕呀。
    cj1324
        10
    cj1324  
       2014-07-18 14:26:05 +08:00
    嘿嘿 我见过不少
    xxx.py

    ```python
    import socket

    socket.setdefaulttimeout(15)
    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3272 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:11 · PVG 21:11 · LAX 06:11 · JFK 09:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.