[Tutor] defined()
Bob Gailer
bgailer at alum.rpi.edu
Tue Apr 4 03:10:34 CEST 2006
Hugo González Monteverde wrote:
> Alan Gauld wrote:
>
>
>> Which language(s) do you know that has such a feature?
>> And why do you consider it so useful that you expect to find
>> it in Python?
>>
>
> I'm not the original poster, but being a perlhead before, I can say it
> exists in Perl. It is very often used too.
>
And you can "roll your own" in Python:
def defined(name):
return name in globals()
> I used to miss it at first, but normally I now do the right thing
> semantically. Counting on the variable being defined or not is simply
> another bit of information. Assigning a value for that case is much cleaner.
>
> It is not used for black magic in Perl, AFAIK. Just normal testing.
>
> Hugo
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list