如何导入另一个.py文件的所有导入

时间:2015-01-31 14:27:49

标签: eclipse python-3.x project system

信息

  • python版本:3
  • 开发环境:eclipse luna

目标

我正在为程序开发一个插件系统。我的想法是创建一个文件,我导入所有插件。此文件是在插件安装过程中生成的(当您单击按钮时:安装插件)。它看起来像是:

import testaddon1
import testaddon2
import bigaddon.startup as bigaddon

当我启动我的程序时,我想导入所有文件/模块以读取一些属性并自动在我的程序中实现插件。

问题

如何启动用不同文件编写的import语句。

file1.py
def test():
   print('test')
file2.py
import file1.py.test as test
file3.py
#run the import commands from file2.py
test()
运行file3.py后的控制台输出:
test

我想要什么

  • 关于如何实现上一个结果的答案
  • 关于如何创建插件系统的不同想法

1 个答案:

答案 0 :(得分:2)

是的,你可以做到。

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

相关问题