Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Overriding adding items to container

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


jyrinxat at mindspringdot

Feb 12, 2002, 8:48 PM

Post #1 of 1 (307 views)
Permalink
Overriding adding items to container

I have a class derived from list (v2.2 is cool ...), and I want to
override its behavior so that a function is called whenever an object is
added to the list (in particular, I want to create a weak reference to
the parent). To wit:

>>> bob = myList()
>>> joe = myItem()
>>> bob.append(joe) # (or insert(joe), or bob[0:0]=[joe], etc.)
>>> joe.parent is bob
1

Is there any good, general way to do this? It seems I can override
__setitem__(), append(), insert(), and others, but it would seem more
elegant just to be able to change one thing. Is this possible? Thanks!

Jyrinx
jyrinxat [at] mindspringdot (spam-proofed)

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.