On Sat, Jul 07, 2007 at 01:08:15PM -0400, Terry Reedy wrote: > > "Nick Coghlan" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > | Georg is correct. A list comprehension like: > | > | [(x * y) for x in seq1 for y in seq2] > | > | expands to the following in 2.x (% prefixes the compiler's hidden > | variables): > | > | %n = [] > | for x in seq1: > | for y in seq2: > | %n.append(x*y) # Special opcode, not a normal call > | > | In py3k it expands to: > | > | def <anon>(outermost): > | %0 = [] > | for x in outermost: > | for y in seq2: > | %0.append(x*y) # Special opcode, not a normal call > | return %0 > | %n = <anon>(seq1) > > Why not pass both seq1 *and* seq2 to the function so both become locals? > The difference of treatment is quite surprising.
I'd be curious if there is anyway to preserve the existing behaviour; class foo: some_list = ('blacklist1', 'blacklist2') known_bad = some_list += ('blah',) locals().update([(attr, some_callable) for attr in some_list]) is slightly contrived, but I use similar code quite often for method generation- both for tests, and standard enough objects. Realize I could do the same via metaclasses, but it's an extra step and not nearly as easy/friendly imo. So... anyway to preserve that trick under py3k? ~harring
pgpTguRRtxF1m.pgp
Description: PGP signature
_______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com