Simple questions on use of objects (probably faq)
Brian Elmegaard
brian at rkspeed-rugby.dk
Thu Mar 9 05:54:11 EST 2006
bruno at modulix <onurb at xiludom.gro> writes:
> So it's time to move to 2.4x !-)
I guess so.
> What is "going wrong" exactly ?
def _add_instance(cls, instance):
_add_instance=classmethod(_add_instance)
cls._instances.append(instance)
gives me:
d:/DTU/80494 $ python.exe ooo.py
Traceback (most recent call last):
File "ooo.py", line 36, in ?
Foo(value)
File "ooo.py", line 6, in __init__
self._add_instance(self)
File "ooo.py", line 9, in _add_instance
_add_instance=classmethod(_add_instance)
UnboundLocalError: local variable '_add_instance' referenced before assignment
d:/DTU/80494 $
> Yeps too. This is called "encapsulation".
Interesting.
> Also, if you intend to use such a solution (with or without multiple
> lists), you may want to add a classmethod to delete instances from the
> list(s).
I will have to study classmethods.
--
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
http://www.rugbyklubben-speed.dk
More information about the Python-list
mailing list