为什么是“import *"坏的? [英] Why is "import *" bad?

查看:64
本文介绍了为什么是“import *"坏的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建议不要在Python中使用import *.

It is recommended to not to use import * in Python.

谁能分享一下原因,以便我下次避免这样做?

Can anyone please share the reason for that, so that I can avoid it doing next time?

推荐答案

  • 因为它在你的命名空间中放入了很多东西(可能会影响之前导入的一些其他对象,而你不会知道它).

    • Because it puts a lot of stuff into your namespace (might shadow some other object from previous import and you won't know about it).

      因为您不确切知道导入了什么,并且无法轻松找到某个内容是从哪个模块导入的(可读性).

      Because you don't know exactly what is imported and can't easily find from which module a certain thing was imported (readability).

      因为你不能使用像 pyflakes 这样很酷的工具来静态检测代码中的错误.

      Because you can't use cool tools like pyflakes to statically detect errors in your code.

      这篇关于为什么是“import *"坏的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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