Python variable assigned by an outside module is accessible for printing but not for assignment in the target module

后端 未结 2 429
春和景丽
春和景丽 2021-01-24 17:42

I have two files, one is in the webroot, and another is a bootstrap located one folder above the web root (this is CGI programming by the way).

The index file in the web

2条回答
  •  醉梦人生
    2021-01-24 18:23

    try this:

    
    def initialize():
        global VAR
        print('Content-type: text/html\n\n')
        print(VAR)
        VAR = 'h'
        print(VAR)
    
    

    Without 'global VAR' python want to use local variable VAR and give you "UnboundLocalError: local variable 'VAR' referenced before assignment"

提交回复
热议问题