0

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?

4

1 回答 1

1

只需使用 调用它a(),它可以通过全局模块范围获得:

def a():
    return "test"


class b:
    def c(self):
        x = a()
        print x

b().c()  # prints "test"

另请参阅此线程:范围规则的简短描述?

于 2013-08-24T07:15:12.437 回答