Re: [python-iter] Resolution at Python 9
- Sun, 11 Mar 2001 06:02:23 -0500 (EST), Clark C. Evans <cce@...> pisze:
> for (,y) in [ (1,'a'), (2,'b') ]: print yYou can't have this syntax, because it already means a different thing:
IMHO having explicit dictionary methods like xkeys and xitems will
__("< Marcin Kowalczyk * qrczak@... http://qrczak.ids.net.pl/
^^ SYGNATURA ZASTĘPCZA
> I think the closest way to do it in Python is to use threads.This is already implemented: look at the Queue module:
> A thread-aware queue which is an iterator at one end and a file-like
> sink at the other, implemented once for all uses. Called Chan in
> Concurrent Haskell. Should be a nice abstraction. Doesn't require
> more magic than is already there.
> Well, so there are three approaches, and the third does fit Python!
To push an item into the Queue, you use q.put(x); to pull the next
item from it, use x = q.get(). If you want a terminator, all you need
to do is agree on a sentinel value. If you want an iterator, you can
use iter(q, sentinel).
The disadvantage is that it's way slow compared to stackframe-based
solutions, and that's why it's not commonly used as an alternative for
push/pull interfaces except where threads are already on the mind of
--Guido van Rossum (home page: http://www.python.org/~guido/)