Need help with Python scoping rules

Dave Angel davea at ieee.org
Wed Aug 26 14:34:26 CEST 2009


Ulrich Eckhardt wrote:
> Jean-Michel Pichavant wrote:
>   
>> class Color:
>>     def __init__(self, r, g,b):
>>           pass
>>     BLACK = Color(0,0,0)
>>
>> It make sens from a design point of view to put BLACK in the Color
>> namespace. But I don't think it's possible with python.
>>     
>
> class Color:
>     ...
>
> setattrib(Color, "BLACK", Color(0,0,0))
>
> Uli
>
>   
Or instead of setattrib,

Color.BLACK = Color(0,0,0)

DaveA



More information about the Python-list mailing list