2011-02-23 82 views
0

我只想类中访问some_object你好:DEF GET()PyThon如何将对象传递给另一个类?

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() 
+0

@S。洛特:责怪该类的web.py教程,并且为方法指定web.py本身,而非OP。 – geoffspear 2011-02-23 18:46:23

+0

some_object是ParentObj.func(数据)的一个实例 – 2011-02-23 18:46:54

+0

做什么???????? – 2011-02-23 18:47:00

回答

0

你可以做some_object类本身的成员。

根据您的'__main__'部分,设置some_objecthello类中的一个成员,像这样:

hello.some_object = some_object 

然后换hello.GET返回类的成员:

class hello: 
    def GET(self, name): 
     return self.some_object 
相关问题