Message389120
I cannot reproduce in Python with either 3.8 or 3.10. (Please try with latter if you can.) I thought the issue might possibly be passing two different dicts, which results in the code being executed as if in a class statement, but it is not.
code = '''
c=[1,2,3,4]
d={'list': [c[i] for i in range(len(c))]}
print(d)
'''
bcode = compile(code, '', 'exec')
gdict = globals()
ldict = {}
exec(bcode, gdict, gdict)
exec(bcode, gdict, ldict)
class C:
c=[1,2,3,4]
d={'list': [c[i] for i in range(len(c))]}
print(d)
prints {'list': [1, 2, 3, 4]} 3 times. Using 'eval' instead of 'exec' gives the same. I presume that code compiled with 'exec' is 'exec'ed even if use eval. |
|
Date |
User |
Action |
Args |
2021-03-19 22:38:53 | terry.reedy | set | recipients:
+ terry.reedy, chrisgmorton |
2021-03-19 22:38:53 | terry.reedy | set | messageid: <1616193533.23.0.0813426742333.issue43481@roundup.psfhosted.org> |
2021-03-19 22:38:53 | terry.reedy | link | issue43481 messages |
2021-03-19 22:38:53 | terry.reedy | create | |
|