PEP 288 was mentioned in one of the lambda threads and so I ended up reading it for the first time recently. I definitely don't like the idea of a magical __self__ variable that isn't declared anywhere. It also seemed to me like generator attributes don't really solve the problem very cleanly. An example from the PEP[1]:
def mygen(): while True: print __self__.data yield None
g = mygen() g.data = 1 g.next() # prints 1 g.data = 2 g.next() # prints 2
I don't get why this isn't good enough:
def mygen(data): while True: print data[0] yield None
data = [None] g = mygen(data) data[0] = 1 g.next() data[0] = 1 g.next()
Using a one-element list is kind of annoying, because it isn't clear out of context that it's just a way of creating shared state. But it's okay, work right now, and provides the exact same functionality. The exception part of PEP 288 still seems interesting.
-- Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org -- http://mail.python.org/mailman/listinfo/python-list