subtle side effect of generator/generator expression

bonono at bonono at
Sun Oct 16 16:20:25 CEST 2005

That is exactly what I meant, in fact. These IO thing are expected to
have side effects so they are not subtle. Generator on the other hand,
is sort of "clever iteratables".

Now that I notice that, Of course I can be sure I would be careful. But
what about the following situation :

I import some function from some third party module which said, "oh, my
function returns a iteratable". Then I can only list(o) if I want to
pass it around or I consume it in only one and only one place. turning
it into a list completely negate what generator is intended
for(generate as much as you need) and using it in only one and only one
place(like your fread example) would IMO means its usage is pretty

Beside, I can do a fseek to rewind a file handle but not a generator

Fredrik Lundh wrote:
> > As when the program/system goes beyond a single module, this behaviour
> > can cause subtle bugs ?
> sure, in the same way as
>     >>> f = open(filename)
>     >>>
>     'hello world\n'
>     >>> # oops!
>     ''
> causes subtle bugs (that is, almost never)
> </F>

More information about the Python-list mailing list