GLOBAL variables in python
Alex Martelli
aleaxit at yahoo.com
Tue Nov 7 09:06:43 EST 2000
"Max Møller Rasmussen" <maxm at normik.dk> wrote in message
news:mailman.973599744.27285.python-list at python.org...
> From: python9999 at my-deja.com [mailto:python9999 at my-deja.com]
>
> >a= myclass()
> >def get():
> > name=a.entry.entry1.get_text()
> > return name
>
> You need to declare it global inside the method:
No, you only need to do that if the method _assigns_
to the global-variable (along some possible execution
path). Not if it only _uses_ ('reads') it.
> a= myclass()
> def get():
> global a
> name=a.entry.entry1.get_text()
> return name
This code is strictly equivalent to that in the
previously quoted snippet, since 'a' is not
assigned-to (along any execution path) within
the get() function anyway.
Alex
More information about the Python-list
mailing list