Setting a Global Default for class construction?

Peter Hansen peter at engcorp.com
Sun Feb 2 20:05:24 EST 2003


Josh English wrote:
> 
> I suspected I was a getting got by a Gotcha! I had to use a global
> statement:
> 
> _Thing = 'it'
> 
> class NewThing:
>         def __init__(self,thing=None):
>                 global _Thing
>                 if thing: self.Thing = thing
>                 else: thing = _Thing

Actually, the above doesn't work for a different reason... You
are not actually assigning to *self.Thing* in the case where
no "thing" is passed in.  And you probably meant to do self.thing
anyway.  And you don't actually need the global statement if all
you are doing is reading from _Thing... ;)

-Peter




More information about the Python-list mailing list