Mar-27-2017, 07:08 AM
first, here is the (nearly) minimalized code by itself:
s="foo = 1\nfor n in range(10):\n x = [n**m for m in range(9)]\nbar = 0" g={} l={} print(s) exec(s,g,l) print(repr(l))secondly here is the output i get:
Output:lt1/forums /home/forums 6> py3 --version
Python 3.5.2
lt1/forums /home/forums 7> cat try.py
s="foo = 1\nfor n in range(10):\n x = [n**m for m in range(9)]\nbar = 0"
g={}
l={}
print(s)
exec(s,g,l)
print(repr(l))
lt1/forums /home/forums 8> py3 try.py
foo = 1
for n in range(10):
x = [n**m for m in range(9)]
bar = 0
Traceback (most recent call last):
File "try.py", line 5, in <module>
exec(s,g,l)
File "<string>", line 3, in <module>
File "<string>", line 3, in <listcomp>
NameError: name 'n' is not defined
lt1/forums /home/forums 9>
it looks like that while executing under exec(), the local namespace is not used in a comprehension. it works as expected under python2:Output:lt1/forums /home/forums 10> py2 --version
Python 2.7.12
lt1/forums /home/forums 11> cat try.py
s="foo = 1\nfor n in range(10):\n x = [n**m for m in range(9)]\nbar = 0"
g={
l={}
print(s)
exec(s,g,l)
print(repr(l))
lt1/forums /home/forums 12> py2 try.py
foo = 1
for n in range(10):
x = [n**m for m in range(9)]
bar = 0
{'x': [1, 9, 81, 729, 6561, 59049, 531441, 4782969, 43046721], 'foo': 1, 'm': 8, 'bar': 0, 'n': 9}
lt1/forums /home/forums 13>
i did not get that empty line that appears to be output by command 10. that's a bug in MyBB somewhere. i take it out and posting puts it back in (could be a bug in the client side code). now it moved it to command 11. got it out this time. but it remove the closing brace of the empty dict assignment to g.