Why I need to declare import as global in function
fredrik at pythonware.com
Mon Nov 28 15:06:49 CET 2005
didier.doussaud at gmail.com wrote:
> I have a stange side effect in my project :
> in my project I need to write "gobal" to use global symbol :
> import math
> def f() :
> global math # necessary ?????? else next line generate an error
> message ?????
what error message?
> print math.pi
you only need global in this case if you assign to the name somewhere
later in the function (e.g. "math = ..." or "import math" or some other
please post the error message (the entire traceback).
More information about the Python-list