[issue7439] Bug or expected behavior? I cannot tell.

Matthew Barnett report at bugs.python.org
Sat Dec 5 20:09:56 CET 2009


Matthew Barnett <python at mrabarnett.plus.com> added the comment:

The problem with the shorthand form is that the generators use the
values that are bound to 'a' and 'p' when they are iterated, not when
they are created. You can test this by inserting:

    a = "X"

just before the assert: you'll get a TypeError later on.

You need something like this:

        m = []
        for (a,p,) in ((2,p2),(3,p3),(5,p5)):
            def gen(a=a, p=p):
                return (a*x for x in p)
            m.append(gen(a, p))

----------
nosy: +mrabarnett

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7439>
_______________________________________


More information about the Python-bugs-list mailing list