Newbie Variable Definition Question
Gerrit Holl
gerrit.holl at pobox.com
Tue Dec 14 11:51:40 EST 1999
Ivan Van Laningham wrote:
> Hi All--
>
> try:
> x=variable
> except NameError:
> variable="default value"
> x=variable
>
> print x
I prefer:
if not locals.has_key('x') or globals.has_key('x'):
x='default value'
--
"Nature abhors a Vacuum"
-- Brian Behlendorf on OSS (Open Sources, 1999 O'Reilly and Associates)
5:49pm up 4 min, 3 users, load average: 0.28, 0.37, 0.17
More information about the Python-list
mailing list