简体   繁体   English

我如何读取代码“from <module> 导入*“使用?

[英]How do I read code where “from <module> import *” is used?

Suppose I read code written by someone else where "from import *" is used, how can I determine what module a function is from? 假设我读取了其他人使用“from import *”编写的代码,我该如何确定函数来自哪个模块? Is this the reason why some people frown upon "from import *"? 这是为什么有些人对“从进口*”皱眉的原因?

Yes, this is why from <module> import * is considered bad style. 是的,这就是为什么from <module> import *被认为是糟糕的风格。 What you can do is remove these * imports one by one, then check which NameError s you get and solve them one by one by explicit imports. 您可以做的是逐个删除这些*导入,然后检查您获得的NameError并通过显式导入逐个解决它们。

from ... import * is the bad style not recommended by PEP8 (python style guide). from ... import *PEP8 (python样式指南)不推荐的坏样式。 There are no ways to know which module is function from except the editing the code (replacing from ... impot * to 'import ...' and looking for errors). 除了编辑代码( from ... impot *替换为'import ...'并寻找错误)之外,没有办法知道哪个模块起作用。 Unfortunately, those errors will occur only when corresponding parts of code is executed. 不幸的是,只有在执行相应的代码部分时才会出现这些错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM