Hi, If you need direct access to some atribute, use object.__getattribute__.
>>> class DefaultAttr(object): ... def __init__(self, default): ... self.default = default ... def __getattribute__(self, name): ... try: ... value = object.__getattribute__(self, name) ... except AttributeError: ... value = self.default ... return value ... >>> x = DefaultAttr(99) >>> >>> print x.a 99 >>> x.a = 10 >>> print x.a 10 >>> On Sun, 30 Jan 2005 13:54:38 -0800 Lowell Kirsh <[EMAIL PROTECTED]> wrote: > I want to create a class called DefaultAttr which returns a default > value for all attributes which haven't been given values yet. It will > work like this: > > >> x = DefaultAttr(99) > >> print x.foo > 99 > >> print x.bar > 99 > >> x.foo = 7 > >> print x.foo > 7 > > I already have a similar class called DefaultDict which works > similarly which I assume would be a good thing to use. > > Lowell > -- > http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list