Existance of of variable

Andreas Kostyrka andreas at kostyrka.org
Wed Jul 13 03:27:53 EDT 2005


Am Montag, den 04.07.2005, 20:25 -0400 schrieb Roy Smith:
> Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote:
> > Should we *really* be encouraging newbies to mess with globals() and
> > locals()? Isn't that giving them the tools to shoot their foot off before
> > teaching them how to put shoes on?
> 
> Why risk damaging perfectly good footwear?
> 
> But, seriously, I agree with you.  The cannonical way to tell if a variable 
> exists in Python is to try to access it and catch any resulting NameError.
Although it should be said that this goes only for variables. obj.value
isn't such a beast (even if some newbies might think so), and would
throw an AttributeError.

Another thing to consider when it comes to footwear: Ruining it once and
enduring the resulting discomfort teaches quite well. And leaves a
respect for the "magic" features of Python that stays the rest of one's
life :)

So I think every newbie at some time of his/her learning process should
probably have fun with all the cool features of Python (be it globals(),
assigning to __builtins__, __getattr__ and derived classes, or what
ever ;) ). Playing alone is not enough, but playing and living to
maintain the code afterwards is very educative ;)
OTOH, perhaps for me it was teaching more, because I have been forced to
maintain by first bigger python application almost for a decade. One
learns quite a bit about software engineering this way ;)

Andreas

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
URL: <http://mail.python.org/pipermail/python-list/attachments/20050713/963de204/attachment.sig>


More information about the Python-list mailing list