我有三個Python文件蟒蛇AttributeError的
one.py
,two.py
,three.py
one.py
從one.py
我打電話
import two as two
two.three()
在two.py
我
def two():
"catch the error here then import and call three()"
import three as three
在
three.py
我
def three():
print "three called"
所以很自然我越來越:
AttributeError: 'function' object has no attribute 'three'
我的問題是:
有沒有辦法有two.py
捕獲錯誤然後導入three.py
和然後致電three()
?
__ _ __ _ __ _ __ _ __編輯_ __ _ __ _ __ _ __ _ __ _V
我可以這樣調用:
two().three()
def two():
import three as three
return three
但我想叫它像這樣:
two.three()
所以基本上它會自動EXEC高清兩():
你能解釋一下你想要什麼來實現(在更廣泛的層面)? –
假設你的意思是說'從兩個進口的兩個'和'從三個進口的三個'來代替我會是正確的嗎? – neirbowj
我正在嘗試創建一個可以調用的全局對象。 所以導入會發生,然後導入後功能將可用。 – Natdrip