我目前正在为程序开发附加系统。我的想法是创建一个文件,在其中导入所有插件。该文件是在插件安装过程中生成的(当您单击按钮:安装插件时)。看起来像这样:
import testaddon1
import testaddon2
import bigaddon.startup as bigaddon
当我启动程序时,我想导入所有文件/模块以读取一些属性并自动在程序中实现插件。
如何启动写入其他文件中的导入语句。
file1.pydef test():
print('test')
file2.py
import file1.py.test as test
file3.py
#run the import commands from file2.py
test()
运行file3.py之后的控制台输出:
test
是的,你可以做到。
file.py
def hello():
print('hello')
file2.py
import file
file.hello()
file3.py
from file2 import *
file.hello()
执行文件3。 greg@ja python file3.py
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句