有一段代码我不明白为什么能够工作。从我的理解来看,它不应该起作用。问题可以如下简单说明:
"Main.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”中我不需要像这样的导入语句:
import x
,请问原因是什么?涉及到IT技术相关内容。from x import functionThatReturnAString()
它如何确定调用此方法?