[Python-3000] Change to class construction? (original) (raw)
Brian Harring ferringb at gmail.com
Sun Jul 8 16:07:42 CEST 2007
- Previous message: [Python-3000] Change to class construction?
- Next message: [Python-3000] Change to class construction?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Jul 07, 2007 at 01:08:15PM -0400, Terry Reedy wrote:
"Nick Coghlan" <ncoghlan at gmail.com> wrote in message news:468FA01A.6040707 at gmail.com... | 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 (outermost): | %0 = [] | for x in outermost: | for y in seq2: | %0.append(x*y) # Special opcode, not a normal call | return %0 | %n = (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 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/python-3000/attachments/20070708/565e6b76/attachment.pgp
- Previous message: [Python-3000] Change to class construction?
- Next message: [Python-3000] Change to class construction?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]