Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6711 > unrolled thread
| Started by | harrismh777 <harrismh777@charter.net> |
|---|---|
| First post | 2011-05-31 01:48 -0500 |
| Last post | 2011-06-01 08:40 +1000 |
| Articles | 7 on this page of 47 — 13 participants |
Back to article view | Back to comp.lang.python
Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-05-31 01:48 -0500
Re: Something is rotten in Denmark... Chris Rebert <clp2@rebertia.com> - 2011-05-31 00:00 -0700
Re: Something is rotten in Denmark... Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-31 01:35 -0600
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-05-31 13:08 +0300
Re: Something is rotten in Denmark... Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-31 12:48 +0200
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-05-31 15:15 +0300
Re: Something is rotten in Denmark... Terry Reedy <tjreedy@udel.edu> - 2011-05-31 13:11 -0400
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-05-31 15:18 -0500
Re: Something is rotten in Denmark... Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-31 16:24 -0600
Re: Something is rotten in Denmark... Terry Reedy <tjreedy@udel.edu> - 2011-05-31 19:14 -0400
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-05-31 19:09 -0500
Re: Something is rotten in Denmark... Terry Reedy <tjreedy@udel.edu> - 2011-06-01 13:11 -0400
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-01 19:40 -0500
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-01 19:50 -0500
Re: Something is rotten in Denmark... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-02 04:37 +0000
Re: Something is rotten in Denmark... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-02 05:14 +0000
Re: Something is rotten in Denmark... Chris Angelico <rosuav@gmail.com> - 2011-06-02 18:02 +1000
Re: Something is rotten in Denmark... Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-06-02 13:00 +0200
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-02 15:51 +0300
Re: Something is rotten in Denmark... Terry Reedy <tjreedy@udel.edu> - 2011-06-02 15:43 -0400
Re: Something is rotten in Denmark... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-03 11:43 +1200
Re: Something is rotten in Denmark... rusi <rustompmody@gmail.com> - 2011-06-02 19:24 -0700
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-03 09:17 +0300
Re: Something is rotten in Denmark... rusi <rustompmody@gmail.com> - 2011-06-05 03:54 -0700
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-05 15:03 +0300
Re: Something is rotten in Denmark... rusi <rustompmody@gmail.com> - 2011-06-05 05:26 -0700
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-05 16:10 +0300
Re: Something is rotten in Denmark... Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-06-03 10:30 +0200
Re: Something is rotten in Denmark... Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-03 11:53 -0600
Re: Something is rotten in Denmark... Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-06-03 12:35 +0200
Re: Something is rotten in Denmark... Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2011-06-03 14:07 +0300
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-03 15:38 -0500
Re: Something is rotten in Denmark... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-06-04 12:40 +1200
Re: Something is rotten in Denmark... Nobody <nobody@nowhere.com> - 2011-06-03 14:07 +0100
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-02 10:44 -0500
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-02 10:55 -0500
Re: Something is rotten in Denmark... Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-02 17:22 +0000
Re: Something is rotten in Denmark... Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-02 11:43 -0600
Re: Something is rotten in Denmark... Terry Reedy <tjreedy@udel.edu> - 2011-06-02 02:02 -0400
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-06-02 11:02 -0500
Re: Something is rotten in Denmark... Martin Manns <mmanns@gmx.net> - 2011-05-31 23:14 +0200
Re: Something is rotten in Denmark... Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-31 15:47 -0600
Re: Something is rotten in Denmark... Martin Manns <mmanns@gmx.net> - 2011-06-01 02:57 +0200
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-05-31 16:53 -0500
Re: Something is rotten in Denmark... harrismh777 <harrismh777@charter.net> - 2011-05-31 17:06 -0500
Re: Something is rotten in Denmark... Chris Angelico <rosuav@gmail.com> - 2011-06-01 08:39 +1000
Re: Something is rotten in Denmark... Chris Angelico <rosuav@gmail.com> - 2011-06-01 08:40 +1000
Page 3 of 3 — ← Prev page 1 2 [3]
| From | Martin Manns <mmanns@gmx.net> |
|---|---|
| Date | 2011-05-31 23:14 +0200 |
| Message-ID | <20110531231456.44d388d7@Fuddel> |
| In reply to | #6711 |
On Tue, 31 May 2011 01:48:05 -0500 harrismh777 <harrismh777@charter.net> wrote: > >>> fs=[] > >>> fs = [(lambda n: i + n) for i in range(10)] > >>> [fs[i](1) for i in range(10)] > [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=== not good > > ( that was a big surprise! . . . ) > ( let's try it another way . . . ) After being confused I figured out it is a 3.x example: ---- $ python Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) [GCC 4.5.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] ---- $ python3.1 Python 3.1.3 (r313:86834, Nov 28 2010, 11:28:10) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> fs=[] >>> fs = [(lambda n: i + n) for i in range(10)] >>> [fs[i](1) for i in range(10)] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] ---- Is this fixed automatically by 2to3? Martin
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2011-05-31 15:47 -0600 |
| Message-ID | <mailman.2335.1306878486.9059.python-list@python.org> |
| In reply to | #6756 |
On Tue, May 31, 2011 at 3:14 PM, Martin Manns <mmanns@gmx.net> wrote: > $ python > Python 2.6.6 (r266:84292, Apr 20 2011, 11:58:30) > [GCC 4.5.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> fs=[] >>>> fs = [(lambda n: i + n) for i in range(10)] >>>> [fs[i](1) for i in range(10)] > [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] This works by accident. >>> [fs[i](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [fs[0](1) for i in range(10)] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> [f(1) for f in fs] [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] The i variable is part of the global scope, and as you iterate over range(10) again it coincidentally takes on the same values as in the original list comprehension. You don't see this in Python 3 because the scope of i is limited to the list comprehension, not global. Cheers, Ian
[toc] | [prev] | [next] | [standalone]
| From | Martin Manns <mmanns@gmx.net> |
|---|---|
| Date | 2011-06-01 02:57 +0200 |
| Message-ID | <mailman.2347.1306889854.9059.python-list@python.org> |
| In reply to | #6757 |
On Tue, 31 May 2011 15:47:33 -0600 Ian Kelly <ian.g.kelly@gmail.com> wrote: > The i variable is part of the global scope, and as you iterate over > range(10) again it coincidentally takes on the same values as in the > original list comprehension. You don't see this in Python 3 because > the scope of i is limited to the list comprehension, not global. I read about the scope change. However, list comprehension scope being global still feels "right" for me because I am still using Python 2. I feel that I should start worrying more about future migration issues. Cheers Martin
[toc] | [prev] | [next] | [standalone]
| From | harrismh777 <harrismh777@charter.net> |
|---|---|
| Date | 2011-05-31 16:53 -0500 |
| Message-ID | <drdFp.23065$iv4.18821@newsfe09.iad> |
| In reply to | #6756 |
Martin Manns wrote:
> After being confused I figured out it is a 3.x example:
Actually, it is a compatibility example between 2.x and 3.x, compare
below for different behavior from two seemingly identical compatible
constructs, one from 3.2, and the other from 2.6.4:
> Python 3.2 (r32:88445, Mar 29 2011, 21:33:57)
> [GCC 4.3.3] on linux2
>>>> fs=[]
>>>> fs = [(lambda n: i + n) for i in range(10)]
>>>> [fs[i](1) for i in range(10)]
> [10, 10, 10, 10, 10, 10, 10, 10, 10, 10] <=========== compare
>>>>
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
> [GCC 4.4.1] on linux2
>>>> fs=[]
>>>> fs = [(lambda n: i + n) for i in range(10)]
>>>> [fs[i](1) for i in range(10)]
> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] <=========== compare
>>>>
Having compared the two, someone please tell me whether the two
are incompatible, mostly compatible, completely incompatible, or
different languages...
,.,, I realize how 3.2 is working (at the moment) but as compared
with the books, and the behavior of 2.6, it sure looks 'broke' to me...
... why would we want to defer lookup of the 'i' in range(10) until the
anonymous function is called, instead of the time that the function
object is returned... inquiring minds want to know...
PS Ian calls the second construct "working by mistake..."
kind regards,
m harris
[toc] | [prev] | [next] | [standalone]
| From | harrismh777 <harrismh777@charter.net> |
|---|---|
| Date | 2011-05-31 17:06 -0500 |
| Message-ID | <RDdFp.20034$4d6.5915@newsfe01.iad> |
| In reply to | #6758 |
harrismh777 wrote: > PS Ian calls the second construct "working by mistake..." oops, actually he called it, "working by accident... "
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-06-01 08:39 +1000 |
| Message-ID | <mailman.2341.1306881560.9059.python-list@python.org> |
| In reply to | #6758 |
On Wed, Jun 1, 2011 at 7:53 AM, harrismh777 <harrismh777@charter.net> wrote: > Having compared the two, someone please tell me whether the two are > incompatible, mostly compatible, completely incompatible, or different > languages... > By implication, every version of Python is incompatible with every other. The 2.7.1 revision notes include: - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links across devices. Suppose some program were depending on this bug. It works under 2.7.0, fails under 2.7.1. Does that mean that 2.7.1 is incompatible with 2.7.0? Chris Angelico
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-06-01 08:40 +1000 |
| Message-ID | <mailman.2342.1306881605.9059.python-list@python.org> |
| In reply to | #6758 |
On Wed, Jun 1, 2011 at 8:39 AM, Chris Angelico <rosuav@gmail.com> wrote: > - Issue #1713: Fix os.path.ismount(), which returned true for symbolic links > across devices. PS. I know nothing about this particular issue, I just skimmed down the release notes and stopped when something caught my eye. Choose another example if you know of a better one. Chris Angelico
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | comp.lang.python
csiph-web