我有三个 python 文件
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:“函数”对象没有属性“三”
我的问题是:
有没有办法two.py
捕获错误然后导入three.py
然后调用three()
?
__ _ __ _ __ _ __ _ __编辑_ __ _ __ _ __ _ __ _ __ _V
我可以这样称呼它:
two().three()
def two():
import three as three
return three
但我想这样称呼它:
two.three()
所以本质上它会自动执行 def two():