On Mon, Feb 17, 2014 at 3:39 PM, Dylan Baker <[email protected]> wrote: > I didn't think that list comprehensions leaked, since they're supposed to be > usable anywhere map() and filter() is used without any additional side > effects. Maybe I'm wrong though.
Python 2.7.5 (default, Oct 27 2013, 05:36:27) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [x for x in xrange(10)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x 9 >>> (y for y in xrange(10)) <generator object <genexpr> at 0x7ff5c3ddc910> >>> y Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'y' is not defined It's one of those warts of the language. They couldn't remove the leaking (until python3) because some programs had grown to implicitly rely on that. Here's a fun one: res = [(lambda: x) for x in xrange(10)] for r in res: print r() -ilia _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
