Daiyue Weng <daiyuew...@gmail.com> writes: > Hi, I defined a global variable in some function like this, > > def some_function(self): > > global global_var > > PyCharm inspection gave me, > > Global variable is undefined at the module level > > How to fix this?
You define the global variable at the module level. "global VVV" (in a function) actually does not define "VVV" as a global variable. Instead, it tells the interpreter that "VVV" should not be treated as a local variable but be looked up in the "global" (usually module) namespace. In order to define "VVV", you must assign a value to it -- either directly in the "global" (i.e. module) namespace or in your function (together with a "global VVV" declaration). -- https://mail.python.org/mailman/listinfo/python-list