Synchronizing methods of a class
Keith Veleba
keith.veleba at gmail.com
Wed Feb 9 11:01:15 EST 2005
Chris,
Q&D example of <<class>>.__dict__.items() not working for me:
>>> import threading
>>> class A(threading.Thread):
... def __init__(self):
... threading.Thread.__init__(self)
... def one(self):
... pass
... def two(self):
... pass
...
>>> a = A()
>>> a.__dict__.items()
[('_Thread__block',
<Condition(<thread.lock object at 0x009BE070>, 0)>),
('_Thread__name', 'Thread-1'),
('_Thread__daemonic', False),
('_Thread__started', False),
('_Thread__target', None),
('_Thread__kwargs', {}),
('_Verbose__verbose', False),
('_Thread__args', ()),
('_Thread__stopped', False),
('_Thread__initialized', True)]
Neither function I added to the A class shows up.
However, I think it's because I'm using an instance of my class vs.
just referencing the class type.
If I type:
A.__dict__items()
I get the correct list:
[('__module__', '__main__'),
('__doc__', None),
('two', <function two at 0x009E21B0>),
('__init__', <function __init__ at 0x009E2170>),
('one', <function one at 0x009E2230>)]
In any case, thanks for the example reference. That's helps me improve
my idea, and I will most likely use the methods in it.
Keith
More information about the Python-list
mailing list