Why I need to declare import as global in function
Fredrik Lundh
fredrik at pythonware.com
Mon Nov 28 09:06:49 EST 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
assignment)
please post the error message (the entire traceback).
</F>
More information about the Python-list
mailing list