sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Scope issue with list comprehension not using local variables in function #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In console:

l = [ 9, 8 ]
d = {
   "A" : [ 1, 2 ]
   , "B" : [ 3, 4 ]
   }

def f():
    l = d["A"]
    return [ i for i in l if i > 1 ]

print( f() )

Result in:
[9,8]

Removing the global variable "l", generates an error in javascript console
ExecutionError: ExecutionError: l is not defined @ 
http://www.brython.info/py_utils.js:34

Caution, one need to reload the page if first test was run since global
variables remain from one run to another

Original issue reported on code.google.com by pedro.ro...@gmail.com on 30 Dec 2012 at 8:43

GoogleCodeExporter commented 9 years ago
Fixed in revision 283 : in [for x in iterable if condition], variables found in 
iterable and condition are passed to the function $list_comp, and are created 
as local variables to this function

Original comment by pierre.q...@gmail.com on 31 Dec 2012 at 9:44