Fire event when variable is Set/Get

Varghjärta varghjarta at gmail.com
Sun Jul 24 23:41:17 EDT 2005


Hey!

I'm a hobby programmer since many years now and I've done most of my
latest 'real application' coding in C#. I've played with python of and
on yet not catching on until a few months ago when I got myself hocked
on it for real and now I love C# _and_ Python.

But there is something that keeps bugging me, and that keeps me from
embracing Python even more as a serious alternative to C#(for me). In
C# I make heavy use of Get & Set, mainly to fire an event that some
property has changed so that one can act on that _if one would need
to. I've grown very used to doing it and it feels like the best way to
make very OO and reusuable and easy to use Classes.

Is there _anything_ that I could do in Python which would allow me to
known when a variable has been set or when it's being fetched to allow
me to fire an event there?.

I seriously _hate_ having to use methods for editing variables
(setVariable1("blah")) since it just adds more code -- or perhaps not
but the code doesn't flow as nicely. So I don't count this as a real
valid option.

This might seem like not such a big thing but to me it's such a
problem that it's driving me to even consider trying out Boo (the
c#/python hybrid) when I get the chance eventhough I think i'd rather
use the _original_ (python) now when i'm almost getting the hang of
it.

How does python coders generally deal with this? Does everyone inherit
from a class and override the methods that sets variables and does the
work from there? I love events and use them heavily -- in GUI apps
what else would one use?

Would be thankful for any pointers that would evolve my pythonic strives.



More information about the Python-list mailing list