Using properties

Leif K-Brooks eurleif at ecritters.biz
Wed May 25 11:29:01 EDT 2005


tkpmep at hotmail.com wrote:
>     name=property(getname,setname,None,None)
> 
> However, it no longer works if I modify getname and setname to
> 
>     def getname(self):
>         return self.name
> 
>     def setname(self,newname="Port2"):
>         self.name=newname

That's because you're actually modifying the property in setname instead
of modifying the normal attribute. It's equivalent to doing:

def setname(self, newname="Port2"):
    self.setname(newname)



More information about the Python-list mailing list