简体   繁体   English

如何在另一个 python 脚本中访问函数内的变量

[英]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.

相关问题 如何在python中的函数内给变量另一个值? - how can I give a variable another value inside a function in python? 如何从 Python 中的另一个文件调用 function 中定义的变量? - How can I call a variable defined inside a function from another file in Python? 我如何声明一个变量并在 python 中的 2 个函数中访问它 - how i can declare a variable and access it inside 2 functions in python 如何在 Python 中访问 class 内的全局变量 - How can I access global variable inside class in Python 如何将变量从一个 Python 脚本传递到另一个? - How can I pass a variable from one Python Script to another? 如何从一个 function 访问另一个变量? - How can i access a variable from one function to another? 访问另一个函数内的Python变量 - Access a Python variable which is inside a function, in another function 如何从python中的另一个类访问变量? - How can I access a variable from another class in python? 如何访问 python 中另一个文件中声明的变量? (不是面向对象) - How can I access a variable declared in another file in python? (Not OOP) 如何从另一个 Python 脚本访问 Python 脚本的动态变量? - How to access a dynamic variable of a Python script from another Python script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM