Calling a generator multiple times
Alex Martelli
aleaxit at yahoo.com
Sat Dec 8 18:14:00 EST 2001
Bruce Eckel wrote:
...
> I believe that this is too restrictive a definition. My experience
> of generators (from C++/STL) is that a generator is simply a
> callable entity that returns an object every time you call it; this
> call takes no arguments so it is "generating" objects rather than
...so a Python generator such as:
def imageneratorhonest(sequence1, sequence2):
for item in sequence1: yield item
for item in sequence2: yield item
isn't a generator...? Unfortunately, clashes with some preexisting
definition are inevitable each time a common term is adopted in a
specifical technical sense in any universe of discourse -- package, module,
function, type, method, class, instance, exception, attribute, item, just
to give a few examples, are all terms which may be usefully used in some
sense or other, but since Python has adopted each of them in one specific
sense (sometimes the same as a few other languages, sometimes not), it's
best to avoid using them in their other senses when talking about Python.
I learned this the hard way when writing about bridge: perfectly reasonable
idioms such as "on the other hand", "the trick is", "a good deal", etc,
cause far too much confusion when used in a universe of language where
"hand", "trick" and "deal" acquire specific, specialized meanings:-).
Alex
More information about the Python-list
mailing list