class index:
def GET(self):
return 'hello'
def POST(self):
data = web.data()
parse_data(data)
display()
def parse_data(data):
data_part=["abc","bcd"]
return data
def display():
data= "here i want to use the same data variable that was sent from parse_data()"
def main():
app = web.application(URLS, globals())
app.run()
display()
if __name__ == "__main__":
main()
我希望在不使用类的情况下通过python中的其他函数访问变量,我该怎么做?我正在尝试使用与其余函数一起使用的变量。
答案 0 :(得分:0)
您可以使用全局变量。
例如:
class index:
def GET(self):
return 'hello'
def POST(self):
data = web.data()
parse_data(data)
display()
data = "your data"
def parse_data():
global data #only use it if you are going to edit the 'data' variable here
data = "edit your data here"
data_part=["abc","bcd"]
def display():
print(data)
def main():
#~ app = web.application(URLS, globals())
#~ app.run()
parse_data()
display()
if __name__ == "__main__":
main()
返回:
edit your data here