[英]Most pythonic way to import all objects in a module as their name in the module
When you import a module, python protects the namespace by importing all objects in that module as module.objectname
instead of objectname
. 导入模块时,python通过将该模块中的所有对象导入为
module.objectname
而不是objectname
来保护命名空间。 import module.objectname as objectname
will import the object as its original name in the module, but writing out every object in this manner would be tedious for a large module. import module.objectname as objectname
导入将导入对象作为模块中的原始名称,但是以这种方式写出每个对象对于大型模块来说将是繁琐的。 What is the most pythonic way to import all objects in a module as their name within the module? 导入模块中所有对象作为模块中名称的最pythonic方法是什么?
You only need to use this form 您只需要使用此表单
import module.objectname as objectname
If you wish to alias the objectname to a different name 如果您希望将对象名别名为其他名称
Usually you say 通常你说
from module import objectname, objectname2, objectname3
There is no "Pythonic" way to import all the objects as from module import *
is discouraged (causes fragile code) so can hardly be called Pythonic 没有“Pythonic”方法导入所有对象,因为不鼓励
from module import *
导致脆弱的代码,所以几乎不能称为Pythonic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.