Python 中未使用的导入会影响性能吗? [英] Do unused imports in Python hamper performance?

查看:58
本文介绍了Python 中未使用的导入会影响性能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 脚本中未使用的导入是否有任何影响?

Is there any effect of unused imports in a Python script?

推荐答案

您使用的名称污染了您的命名空间,这些名称可能会干扰您的变量并占用一些内存.
此外,您将有更长的启动时间,因为程序必须加载模块.

You pollute your namespace with names that could interfere with your variables and occupy some memory.
Also you will have a longer startup time as the program has to load the module.

无论如何,我不会因此变得过于神经质,就好像您正在编写代码一样,您最终可能会在修改代码时不断编写和删除 import os.一些 IDE 作为 PyCharm 检测未使用的导入,因此您可以在代码完成或接近完成后依赖它们.

In any case, I would not become too neurotic with this, as if you are writing code you could end up writing and deleting import os continuously as your code is modified. Some IDE's as PyCharm detect unused imports so you can rely on them after your code is finished or nearly completed.

这篇关于Python 中未使用的导入会影响性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆