On 9/3/05, Nick Coghlan <[EMAIL PROTECTED]> wrote:
[...]
> Playing well with generator expressions comes for free, too:
>
> print " ".join(str(x*x) for x in range(10))
> => output(*(x*x for x in range(10)))
Hmm... This prompts a coding question - is it possible to recognise
which arguments to a function are generators, so that you could write
output(1, 2, [3,4], (c for c in 'abc'), 'def', (5, 6))
and get
1 2 [3, 4] a b c def (5, 6)
?
At the simplest level, an explicit check for types.GeneratorType would
work, but I'm not sure if there's a more general check that might
might work - for example, iter((1,2,3)) may be a candidate for looping
over, where (1,2,3) clearly (? :-)) isn't. Maybe "iter(arg) is arg" is
the right check...
Of course, there's a completely separate question as to whether magic
this subtle is *advisable*...
Paul.
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com