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


Groups > comp.lang.python > #25970

Re: What's wrong with this code?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'dynamically': 0.07; 'statically': 0.07; 'subject:code': 0.07; 'python': 0.09; 'none.': 0.09; 'objects.': 0.09; 'semantics': 0.09; 'language,': 0.11; 'confusion': 0.16; 'meanwhile': 0.16; 'merely': 0.16; 'x).': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'element': 0.17; '(or': 0.18; 'variable': 0.20; 'trying': 0.21; 'work,': 0.22; 'example': 0.23; 'second': 0.24; 'header:In-Reply- To:1': 0.25; 'values': 0.26; 'andrew': 0.27; 'message- id:@mail.gmail.com': 0.27; "doesn't": 0.28; 'remains': 0.29; 'unchanged': 0.29; 'objects': 0.29; 'code': 0.31; 'to:addr:python- list': 0.33; 'languages': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'subject:with': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'real': 0.61; 'between': 0.63; 'different': 0.63; 'more': 0.63; 'jul': 0.65; 'subject:this': 0.84; 'to:name:python': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=33mVSaPaijM8Z2ILOQIWrzzzrlB1pxLxC8BXqdT42dg=; b=rkQMjQTZ4j9IhukjXwCt4GR607+k9F0JzhAhvhcjJkT8gIC7aGmwlIUKO9EBYBlXsK XKReLFBtOSS08jNupk6HuIPByCIk85ybWKH5IuLs63jW+mjBXqvLw34xOmyA/oLeQKZm 97owkvZnj46oUPfnnRVnPOpZp+9B2VxtNLzoMsLCfa6HJyuaH0Ti6b2/QvdEUcyoPtmD 1M3APwDYGri4mTINitOjl30ppAmedy71Inj2U2RDNiSpYH90GrM+LkqTjO1uJ0sCDLjg o/u+4WYVEHoSpo1vtKfRM85vk1Oq50A1IqwmVcoHGNn5bvJyEl/GRwQKYzHR1ce3xMoM BPLA==
MIME-Version 1.0
In-Reply-To <BKmPr.135207$Hs3.55909@fx08.am4>
References <mailman.2478.1343055006.4697.python-list@python.org> <BKmPr.135207$Hs3.55909@fx08.am4>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 24 Jul 2012 02:26:28 -0600
Subject Re: What's wrong with this code?
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2524.1343120256.4697.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343120257 news.xs4all.nl 6929 [2001:888:2000:d::a6]:46042
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25970

Show key headers only | 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