Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #25956
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'none,': 0.05; 'dynamically': 0.07; 'none)': 0.07; 'statically': 0.07; 'subject:code': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variables,': 0.09; 'gui': 0.11; 'language,': 0.11; 'message-id:@dough.gmane.org': 0.16; 'overwriting': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'which,': 0.16; 'wrote:': 0.17; 'variables': 0.17; '(not': 0.20; 'variable': 0.20; 'names.': 0.22; 'example': 0.23; 'programming': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'possibly': 0.27; 'question': 0.27; 'andrew': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'subsequently': 0.29; "i'm": 0.29; 'standards': 0.30; 'code': 0.31; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'code:': 0.33; 'changed': 0.34; 'thanks': 0.34; 'subject:?': 0.35; 'received:org': 0.36; 'totally': 0.36; 'subject:with': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'as:': 0.75; 'subject:this': 0.84; 'flame': 0.84; 'reveal': 0.84; 'received:89': 0.86 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: What's wrong with this code? |
| Date | Tue, 24 Jul 2012 07:23:37 +0100 |
| References | <mailman.2478.1343055006.4697.python-list@python.org> <BKmPr.135207$Hs3.55909@fx08.am4> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-89-243-205-160.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
| In-Reply-To | <BKmPr.135207$Hs3.55909@fx08.am4> |
| X-Antivirus | avast! (VPS 120723-2, 23/07/2012), Outbound message |
| X-Antivirus-Status | Clean |
| 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.2518.1343110960.4697.python-list@python.org> (permalink) |
| Lines | 67 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1343110960 news.xs4all.nl 6912 [2001:888:2000:d::a6]:57268 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:25956 |
Show key headers only | View raw
On 24/07/2012 02:19, Andrew Cooper wrote: > On 23/07/2012 15:50, Stone Li wrote: >> I'm totally confused by this code: >> >> Code: >> >> a = None >> b = None >> c = None >> d = None >> x = [[a,b], >> [c,d]] >> e,f = x[1] >> print e,f >> c = 1 >> d = 2 >> print e,f >> e = 1 >> f = 2 >> print c,d >> >> Output: >> >> None None >> None None >> 1 2 >> >> >> >> I'm expecting the code as: >> >> None None >> 1 2 >> 1 2 >> >> >> >> What's wrong? >> And this question made my GUI program totally out of control. >> Thanks > > c = 1 and d = 2 are overwriting the variable c (= None) and d (= None) > with new variables 1 and 2. As x already captured c and d while they > were none, the variables e and f do not change (not would the, even if > you subsequently changed x) > > Python is a statically scoped language, whereas the functionality you > are expecting would be an example of dynamically scoped. > > Care to reveal your programming background? > > ~Andrew > <duck and cover> strictly speaking Python doesn't have variables, it has names. This will possibly start a flame war which, by the standards of this ng/ml, will be an intense conflagration, hence the duck and cover. </duck and cover> -- Cheers. Mark Lawrence.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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