python flask 如何获取定义的全局变量值
PHPz
PHPz 2017-04-18 10:25:34
0
3
877

如图,服务器回调到handler_access_times 函数里,定义了 g_times_map 这个全局的map变量,当客户端主动请求
get_access_times接口的时候,g_times_map 这个却始终为空怎么解决,求大神告知啊,python 这个全局变量怎么这么头疼啊

PHPz
PHPz

学习是最好的投资!

reply all(3)
伊谢尔伦

http://stackoverflow.com/ques...
This link has a solution, use the database to save data locally

小葫芦

global variables should be defined outside the function.

x = 1
def f():
    global x
    print(x)
def add():
    global x
    x += 1
add()
f()
黄舟

If you assign a value to g_times_map outside the function, then you do not need a global statement inside the function, and you can still reference the value of g_times_map outside the function. Although I don't know what you want to do, but depending on whether you are using global g_times_map in two functions, you may also be using it in multiple functions, which is easy to make mistakes. If you just want these functions to reference the value of g_times_map outside the function, there is no need to use the global statement.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!