On Mon, 17 Dec 2007 18:18:11 +1100, bambam wrote: > I wish to create a generic container object, devlist, such that > > devlist.method(arguments) > > runs as > > for each dev in devlist.pool: > dev.method(arguments) > > and > s = devlist.method(arguments) > > runs as > > for each dev in devlist.pool: > s.append(dev.method(arguments)) > > ...but it is outside my ability to do so. > > Can anyone provide an example of how to do that?
If I've understood you correctly, I don't think it can be done. It looks to me that you want: s = instance.method() and instance.method() to do completely different things. This is a bad idea and a recipe for confusion. In any case, it is not possible, because the instance method cannot know whether its result is being assigned to a name or just thrown away. I may have misunderstood what you are trying to do. Please feel free to explain in more detail, perhaps with an example. By the way, the correct way to get the result you want is to have devlist.method() work as in your first example, and then do this: s.extend(devlist.method()) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list