I am new to Python, and I am facing a problem:
def a(): ....
class b :
def c():
x=a()
My function a
is defined outside of the class, and I need it to access inside the class in function c
. How should I do this?
I am new to Python, and I am facing a problem:
def a(): ....
class b :
def c():
x=a()
My function a
is defined outside of the class, and I need it to access inside the class in function c
. How should I do this?
只需使用 调用它a()
,它可以通过全局模块范围获得:
def a():
return "test"
class b:
def c(self):
x = a()
print x
b().c() # prints "test"
另请参阅此线程:范围规则的简短描述?