[英]Exporting a variable in a Tornado class to another module
I'm using the Tornado framework
and have a Websockethandler
, which receives data from the client and the value is stored in a variable. 我正在使用
Tornado framework
并拥有一个Websockethandler
,它从客户端接收数据并将值存储在变量中。 How can I send that variable to another module. 如何将该变量发送到另一个模块。 This is the code (partial):
这是代码(部分):
#module a.py
class Handler(tornado.websocket.WebSocketHandler):
@tornado.web.asynchronous
@gen.engine
def on_message(self, event):
data = urlparse.parse_qs(event)
event= data.get('type')
How can the variable event
be passed to module b.py
如何将变量
event
传递给模块b.py
Thanks 谢谢
Make a function in module b.py
, for example on_message
and pass it your event
variable: 在模块
b.py
一个函数,例如on_message
并将它传递给你的event
变量:
b.py
: b.py
:
def handle_event(new_event):
print new_event
a.py
: a.py
:
import b
class Handler(tornado.websocket.WebSocketHandler):
@tornado.web.asynchronous
@gen.engine
def on_message(self, event):
data = urlparse.parse_qs(event)
event= data.get('type')
b.handle_message(event) # this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.