Property In Python

S

sushant.sirsikar

Hi,
I want to know how we can write Properties in Pyhton.Any one knows
good doc for this one?
Thanks
 
G

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)
 
B

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.")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top