Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'assign': 0.07; 'variables': 0.07; 'arrays': 0.09; 'emulate': 0.09; 'global,': 0.09; 'latter': 0.09; 'referenced': 0.09; 'though...': 0.09; 'variable,': 0.09; 'variables.': 0.09; 'python': 0.11; 'assume': 0.14; 'creates': 0.14; 'bind': 0.16; 'declared': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'immutable,': 0.16; 'objects.': 0.16; 'overwriting': 0.16; 'reminded': 0.16; 'scope,': 0.16; 'variable.': 0.16; 'wrong).': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'not,': 0.20; 'header :User-Agent:1': 0.23; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "i'm": 0.30; 'work.': 0.31; '(which': 0.31; '(unless': 0.31; 'object.': 0.31; 'workaround': 0.31; 'alone': 0.33; 'could': 0.34; 'problem': 0.35; 'objects': 0.35; 'but': 0.35; 'picking': 0.36; 'subject:?': 0.36; 'list': 0.37; 'message- id:@gmail.com': 0.38; 'thank': 0.38; 'confirmed': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'read': 0.60; 'most': 0.60; 'new': 0.61; 'simply': 0.61; "you're": 0.61; 'first': 0.61; 'you.': 0.62; 'email addr:gmail.com': 0.63; 'name': 0.63; 'real': 0.63; 'here': 0.66; 'default': 0.69; 'fact,': 0.69; 'suspicion': 0.84 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 29 Jun 2013 08:02:17 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Closures in leu of pointers? References: <2a2072e3-4b12-4ada-872c-1240d2379928@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372514543 news.xs4all.nl 15900 [2001:888:2000:d::a6]:45870 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49420 On 06/29/2013 05:21 AM, cts.private.yahoo@gmail.com wrote: > Thank you. You reminded me of the (weak) workaround of using arrays > and confirmed my suspicion that I although I can read the variable, I > won't be able to write to it. I still don't understand why not, > though... The real problem here is that you don't understand how python variables work. And in fact, python does not have variables. It has names that bind to objects. If you assign a value to a name, you're not overwriting a variable, you're rebinding a name to a new object in the default scope (unless it's declared global, or nonlocal in python 3, the latter I assume uses the same scope in which it was first declared, but I could be wrong). Since the name is in the local scope, the original name in the caller's scope is still bound to its original object. Furthermore, most primitive objects in python (strings, ints, etc) are immutable, which means they can *never change*. "Writing" to a variable simply dereferences the old object (which may still be referenced in the caller's scope) and creates a new object and binds it to the name. A list is mutable, which is why it's one solution to emulate a variable. > As for python 3 ... "nonlocal"? I see I'm not alone in picking > obnoxious names ... nonlocal at least has meaning.