Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25970

Re: What's wrong with this code?

References <mailman.2478.1343055006.4697.python-list@python.org> <BKmPr.135207$Hs3.55909@fx08.am4>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-07-24 02:26 -0600
Subject Re: What's wrong with this code?
Newsgroups comp.lang.python
Message-ID <mailman.2524.1343120256.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jul 23, 2012 at 7:19 PM, Andrew Cooper <amc96@cam.ac.uk> wrote:
> Python is a statically scoped language, whereas the functionality you
> are expecting would be an example of dynamically scoped.

While it's true that Python is statically scoped, that has nothing at
all to do with the code from the OP's question, which contains only
one (global) scope anyway.

The real issue is confusion between name binding and object mutation.
By reassigning c and d, the OP is evidently trying to mutate the list
named x (or to be more precise, the list that is the second element of
the list named x).  But this doesn't work, because name-binding
doesn't mutate objects as it does in languages with variable semantics
(C, for example); it merely rebinds the names to different objects.  c
and d end up bound to values that weren't in the list to begin with,
meanwhile the list remains unchanged and e and f are still just bound
to None.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What's wrong with this code? Stone Li <viewfromoffice@gmail.com> - 2012-07-23 22:50 +0800
  Re: What's wrong with this code? Andrew Cooper <amc96@cam.ac.uk> - 2012-07-24 02:19 +0100
    Re: What's wrong with this code? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-07-24 07:23 +0100
    Re: What's wrong with this code? Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-24 03:38 -0400
    Re: What's wrong with this code? Ian Kelly <ian.g.kelly@gmail.com> - 2012-07-24 02:26 -0600
  Re: What's wrong with this code? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-24 09:47 +0200
    Re: What's wrong with this code? Chris Angelico <rosuav@gmail.com> - 2012-07-24 18:24 +1000
      Re: What's wrong with this code? Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-07-24 12:05 +0200
    Re: What's wrong with this code? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-24 08:26 +0000
    Re: What's wrong with this code? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-07-24 11:34 +0200
  Re: What's wrong with this code? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-07-24 10:34 +0200

csiph-web