Need help with Python scoping rules

Jan Kaliszewski zuo at
Wed Aug 26 22:48:01 CEST 2009

26-08-2009 o 09:03:27 Ulrich Eckhardt <eckhardt at> 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))

Or simpler:

     class Color:

     Color.BLACK = Color(...)



PS. Obviously, that's nothing special (there is no problem with
creating such "recursive" references in Python).

Jan Kaliszewski (zuo) <zuo at>

More information about the Python-list mailing list