Need help with Python scoping rules

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Aug 27 13:17:32 CEST 2009


Ulrich Eckhardt wrote:
> 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))
>>     
>
> Apart from it being "setattr" and not "setattrib", a simple
>
>   Color.BLACK = Color(0,0,0)
>
>   

Obviously ... I'll remember that.

JM



More information about the Python-list mailing list