PyThon如何将对象传递给另一个类?

时间:2011-02-23 18:40:43

标签: python

我只想在类hello中访问some_object:def GET()

from wsgiref.simple_server import make_server
import web

urls = (
    '/(.*)', 'hello'
)

class hello:
    def GET(self, name):
        return some_object


if __name__ == '__main__':

    data = []
    some_object = ParentObj.func(data)

    app = web.application(urls, globals())
    app.run()

1 个答案:

答案 0 :(得分:0)

你可以让some_object成为班级本身的一员。

'__main__'部分下,将some_object设置为hello类的类成员,如下所示:

hello.some_object = some_object

然后更改hello.GET以返回班级成员:

class hello:
    def GET(self, name):
        return self.some_object