[英]How can I access a variable inside a function in another python script
I have a file textrecive.py which contains the variable body我有一个包含变量body的文件textrecive.py
from threading import Thread
import mimetypes
from flask import Flask, Response, request
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/sms", methods=['GET', 'POST'])
def sms_reply():
global body
body = request.values.get('Body').lower()
who = request.values.get('From').lower()
print(who)
resp = MessagingResponse()
print(body)
resp.message(input('what would you like to say'))
return Response(str(resp), mimetype="application/xml"), body
while True:
if __name__ == '__main__':
Thread(target = app.run()).start()
I would like to access the body variable in another script so I can be informed of what the message is saying.我想在另一个脚本中访问body变量,这样我就可以知道消息在说什么。
Any help would be greatly appreciated thanks!任何帮助将不胜感激谢谢!
I also wanted to add that I am using an ngrok server (Port:5000) to communicate between the python script/twilio api and my phone.我还想补充一点,我正在使用ngrok服务器(端口:5000)在 python 脚本/twilio api 和我的手机之间进行通信。
在研究了一段时间后,我遇到了这个stackoverflow 页面,它允许我使用多线程同时运行烧瓶应用程序和我的脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.