一段代码有效,我不明白为什么。根据我的理解,它不应该起作用。问题在下面很容易说明:
“主要.py”
from x import * #class x is defined
from y import * #class y is defined
xTypeObj = x()
yTypeObj = y()
yTypeObj.func(xTypeObj)
“x.py”
class x(object):
def __init__...
...
def functionThatReturnsAString(self):
return "blah"
“y.py”
#NO IMPORT STATEMENT NEEDED?? WHY
class y(object):
def __init__...
...
def func(self, objOfTypeX):
print(objOfTypeX.functionThatReturnsAString())
我的问题是为什么我不需要在“y.py”类型的导入语句
from x import functionThatReturnAString()
它如何确定如何调用此方法?