这么多年了,我还是不喜欢用Python来搜索globals。我的问题出现在一个uWSGI应用程序中,在哪里
init()
BROWSER = webdriver.Firefox()
申报后
global BROWSER
globaltest.py
:
#!/usr/bin/python3
'''
Test of keyword `global`
'''
GLOBALTEST = None
def init():
global GLOBALTEST
GLOBALTEST = 'Something'
if __name__ == '__main__':
print('before init: GLOBALTEST', GLOBALTEST)
init()
print(' after init: GLOBALTEST', GLOBALTEST)
执行:
jcomeau@bendergift:/tmp$ ./globaltest.py
before init: GLOBALTEST None
after init: GLOBALTEST Something
jcomeau@bendergift:/tmp$ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from globaltest import *
>>> GLOBALTEST
>>> init()
>>> GLOBALTEST
>>>