I have three python files
one.py, two.py, three.py
one.py
from one.py I call
import two as two
two.three()
in two.py I have
def two():
"catch the error here then import and call three()"
import three as three
in three.py I have
def three():
print "three called"
so naturally I am getting:
AttributeError: 'function' object has no attribute 'three'
My question is:
Is there a way to have two.py capture the error then import three.py and then call three()?
______________edit________________V
I can call it like this:
two().three()
def two():
import three as three
return three
but I would like to call it like so:
two.three()
So essentially it would auto exec def two():
from two import twoandfrom three import threeinstead?twodoes not containthreewhen you import it; so you should get an error. But your error suggests thatoneseestwoas a function, not as a module. This is impossible with the code you give: you probably havefrom two import two, as @neir suggests?