Naive Question

Michael Hudson mwh21 at cam.ac.uk
Sat Dec 4 07:17:45 EST 1999


jim kraai <jkraai at murl.com> writes:

> Greetings,
> 
> If I have:
> 
> class contrived_collection:
> 	def __init__(self):
> 		self.item = [{1,2},{3,4},{5,6}]
> 
> a = contrived_collection()
> b = a.item[2]
> 
> How can I ask b what it is a member of?

You can't, at least not without basically adding the information
yourself. Watch out for cycles!
 
> I need to somehow know later in processing that:
> 1. b is a member of a.item
> 2. a.item is a member of a

Hmm... what are you trying to do? Have you looked at Acquisition:

http://www.zope.org/Members/Amos/WhatIsAcquisition

(which is zope biased; there may be another more generic intro
somewhere but I can't find it just now).

It s a very cute method for dealing with some problems a bit like
this.

Cheers,
Michael




More information about the Python-list mailing list