import modx和modx import *有什么区别? [英] What is the difference between import modx and from modx import *?
问题描述
如果我要导入一些名为modx的模块,那么与modx import * $ b的说法有什么不同?
If I were to import some module called modx, how would that be different from saying
from modx import *
不是所有内容都是从每种方式导入的吗?这只是为了澄清。
Wouldn't all the contents be imported from each either way? This is in python just to clarify.
推荐答案
如果你导入somemodule
包含的全局变量将通过 somemodule.someglobal
提供。如果你从somemodule import * 所有的全局变量(或
__ all __
中列出的那些全局变量)将成为全局变量,即你可以使用 someglobal
访问它们,而不需要前面的模块名称。
If you import somemodule
the contained globals will be available via somemodule.someglobal
. If you from somemodule import *
ALL its globals (or those listed in __all__
if it exists) will be made globals, i.e. you can access them using someglobal
without the module name in front of it.
使用不推荐使用模块导入*
,因为它会使全局范围变得混乱,如果从多个模块导入内容,则可能会发生冲突并覆盖现有的类/函数。
Using from module import *
is discouraged as it clutters the global scope and if you import stuff from multiple modules you are likely to get conflicts and overwrite existing classes/functions.
这篇关于import modx和modx import *有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!