[英]Is there a way to import all functions(using *) from a file without the imports of that file?
我有两个.py文件
Helper.py
SomeClass.py
假设两个文件都导入 sys 的例子
我想像这样将Helper.py
导入到SomeClass.py
中: from helper.py import * (因为我需要其中的所有函数)
但我不想从任何文件中删除 import sys 因为这两个文件并不是真正的 go 手动。
有没有办法导入 * 并排除导入/从...导入另一个文件?
您可以定义__all__
模块。
在您的Helper.py
文件中,添加一行
__all__ = ["foo", "bar"] # All the objects you want to export
然后在SomeClass.py
中使用from helper.py import *
,这只会导入__all__
中指定的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.