Property In Python

2006-04-21 Thread sushant . sirsikar
Hi,
  I want to know how we can write Properties in Pyhton.Any one knows
good doc for this one?
Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Property In Python

2006-04-21 Thread gangesmaster
class person(object):
def _get_age(self):
return self.__age
age = property(_get_age) # a read-only property

def _get_name(self):
return self.__name
def _set_name(self, value):
self.__name = value
name = property(_get_name, _set_name)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Property In Python

2006-04-21 Thread bayerj
>>> print property.__doc__
property(fget=None, fset=None, fdel=None, doc=None) -> property
attribute

fget is a function to be used for getting an attribute value, and
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 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.")

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Property In Python

2006-04-21 Thread B Mahoney
I started with the "How-To Guide for Descriptors" by Raymond Hettinger
http://users.rcn.com/python/download/Descriptor.htm

It is one of several docs on the "New-style Classes" page at python.org
http://www.python.org/doc/newstyle/

-- 
http://mail.python.org/mailman/listinfo/python-list