PEP 288 ponderings

Nick Coghlan ncoghlan at iinet.net.au
Sun Jan 2 02:22:14 EST 2005


Ian Bicking wrote:
> 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.

Uh, isn't shared state what classes were invented for?

Py> class mygen(object):
...   def __init__(self, data):
...     self.data = data
...   def __iter__(self):
...     while 1:
...       print self.data
...       yield None
...
Py> g = mygen(0)
Py> giter = iter(g)
Py> giter.next()
0
Py> g.data = 1
Py> giter.next()
1

Cheers,
Nick.


-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list