我有三个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