On Sat, Jul 10, 2010 at 3:00 PM, daveloeffler <dave.loeff...@gmail.com> wrote: > > > On 10 July, 13:05, Johannes <dajo.m...@web.de> wrote: >> Hi list, >> i just tried the following pice of code and returned an unexcepted, but >> explainable behavior: >> >> sage: p = los[0][1] >> A lattice polytope: 3-dimensional, 4 vertices. >> sage: list(set([ p for p in reduce (lambda x,y : x + y,[ f.points() >> for f in p.facets() ])])) >> [0, ... some list of points ] >> sage: p >> 34 >> >> my old variable p = los[0][1] is overwritten by the one i used in the >> list comprehension. Is this the default sage or python behavior? or is >> this an bug in sage/python? > > This is standard Python behaviour. A list comprehension doesn't have > its own scope, so the "p" used in the list comprehension overwrites > the other "p" previously declared in the same scope. I agree that this > can be annoying, but it's a fact of life in Python programming.
... albiet, a temporary one (!): wst...@redhawk:~$ python3.1 Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [i*i for i in range(10)] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] >>> i Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'i' is not defined The point being that in Python 3.x this fact of life is change. Eventually, Sage will switch to Python 3.x. William -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org