Python Property method for protecting private variables -
i'm trying learn python's oops concepts , i'm trying learn handling private data in python. got know can achived using "property" method , i'm executing below code thowing me error while i'm trying access attribute.
class hello(object): def __init__(self, name): self.__name = name def __setname(self, name): self.__name = name def __getname(self): return self.__name name = property(__setname, __getname) h = hello("saumya") print h.name typeerror: __setname() takes 2 arguments (1 given)
can anynody me , going wrong ?
thanks, saumya
the property
function takes getter first, setter:
name = property(__getname, __setname)
Comments
Post a Comment