global event listeners

Josiah Carlson jcarlson at uci.edu
Wed Nov 17 01:17:23 EST 2004


"Hunter  Peress" <hunterp at gmail.com> wrote:
> 
> i suppose i could do this, and have an "if self.__name__ ==
> what_im_looking_for and type(self) == what_im_also_looking_for"
> 
> next is how can i make every object in a given runtime inherit from
> this class

Before I answer your question, I will state that it is common courtesy
to quote the relevant portions of the email you are replying to; it
makes picking up on the conversation easier.

class counter(object):
    counter = 0
    def __init__(self, value):
        self.__value = value
    
    def get_v(self):
        return self.__value
    def set_v(self, val):
        self.__value = val
        counter.counter += 1
    value = property(get_v, set_v)

>>> a = counter(1)
>>> b = counter(2)
>>> a.counter
0
>>> b.counter
0
>>> a.value = 0
>>> a.counter
1
>>> b.counter
1
>>>


 - Josiah




More information about the Python-list mailing list