什麼是Python中執行此類型的導入運行導入與在Python多個子目錄
文件的最好方式進口上述功能於位置的一個/ ne_one/one_two /」
fielname: two.py
def foo():
print "venkatttt!"
主要文件:main.py這
s = __import__("one.one_one.one_two.two", fromlist=[])
function_class = getattr(s,"one_one")
function_class1 = getattr(function_class,"one_two")
function_class2 = getattr(function_class1,"two")
print s
print function_class
print function_class1
print function_class2
function_class2.foo()
輸出代碼:
<module 'one' from '/opt/auto/src/ex/one/__init__.pyc'>
<module 'one.one_one' from '/opt/auto/src/ex/one/one_one/__init__.pyc'>
<module 'one.one_one.one_two' from '/opt/auto/src/ex/one/one_one/one_two/__init__.pyc'>
<module 'one.one_one.one_two.two' from '/opt/auto/src/ex/one/one_one/one_two/two.py'>
venkatttt!
我正在尋找爲執行此導入
'import one.one_one.one_two.two'有什麼問題? – phihag 2012-07-17 11:49:40
@phihag我試圖執行一個運行時導入,所以病不能夠使用導入one.one_one.one_two.two – Ragav 2012-07-17 11:51:41