limodou wrote: > On 2/10/06, john peter <[EMAIL PROTECTED]> wrote: (snip)
>> what do i have to do if i want my application code to have >>read-only >> attributes? >> > I think you may consider property() built-in function: > > property( [fget[, fset[, fdel[, doc]]]]) > > Return a property attribute for new-style classes (classes that derive > from object). > fget is a function s/function/callable/ > for getting an attribute value, likewise fset is a > function for setting, and fdel a function for del'ing, an attribute. > Typical use is to define a managed attribute x: > > > class C(object): > def __init__(self): self.__x = None > def getx(self): return self.__x > def setx(self, value): self.__x = value > def delx(self): del self.__x > x = property(getx, setx, delx, "I'm the 'x' property.") Note that you don't need to define all three accessors. For a 'read-only' attribute, just define the getter: class ReadOnly(object): def __init__(self, x): self._x = x x = property(fget=lambda self: self._x) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list