Fire event when variable is Set/Get

Varghjärta varghjarta at gmail.com
Mon Jul 25 00:37:10 EDT 2005


Thank you!

Wow, this might be exactly what I want! Thanks to the pythonness
(syntax) the code might even be shorter then implementing it in C#!

Gonna go and play around with this some more(now), and can't wait til
I get home (there will be some massive code cleaning).

I wonder why I've never come across this before, feels like i've
googled alot these last weeks.

Python has grown in my eyes.

On 24 Jul 2005 21:06:07 -0700, tharaka <tharakawick at gmail.com> wrote:
> You are in luck because Python has "Properties" just like .NET.
> 
> For details lookup the documentation of the built-in function
> property(). I'll just paste it here:
> 
> 
> property( [fget[, fset[, fdel[, doc]]]])
> 
> Return a property attribute for new-style classes (classes that derive
> from object).
> fget is a function 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 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.")
> 
> 
> ... now u can use x like any variable and, python will get & set it
> through the appropriate methods. Hope this answers your question.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list