Path: csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'cpython': 0.05; 'interpreter.': 0.07; 'works.': 0.07; '"a"': 0.09; 'abstraction': 0.09; 'garbage': 0.09; 'immutable': 0.09; 'objects.': 0.09; 'underlying': 0.09; 'python': 0.10; 'interpreter': 0.15; 'assignments.': 0.16; 'assigns': 0.16; 'count,': 0.16; 'expression.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'overwriting': 0.16; 'pointers.': 0.16; 'sees': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'case.': 0.18; 'pointer': 0.18; 'variable': 0.18; 'assign': 0.22; 'sep': 0.22; 'suppose': 0.22; "python's": 0.23; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'fri,': 0.27; 'object,': 0.27; 'values': 0.28; "we're": 0.30; 'work.': 0.30; 'certainly': 0.30; 'probably': 0.31; 'certain': 0.31; 'statement': 0.32; 'useful': 0.33; 'michael': 0.33; 'message-id:@gmail.com': 0.34; 'case,': 0.34; 'but': 0.36; '(and': 0.36; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'difference': 0.38; 'names': 0.38; 'does': 0.39; 'received:192': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'forget': 0.60; 'care': 0.60; 'skip:u 10': 0.61; 'yes': 0.62; 'charset:windows-1252': 0.62; 'more': 0.63; 'between': 0.65; 'talking': 0.67; 'secret': 0.72; 'physical': 0.72; 'works)': 0.84 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Fri, 11 Sep 2015 18:34:07 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python handles globals badly. References: <14afe27e-0bd5-410f-8e64-0f31d496ebf2@googlegroups.com> <55F36B4C.9020007@gmail.com> <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> In-Reply-To: <1442016698.95299.381478313.2487CA0E@webmail.messagingengine.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442018052 news.xs4all.nl 23729 [2001:888:2000:d::a6]:60725 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96377 On 09/11/2015 06:11 PM, random832@fastmail.us wrote: > On Fri, Sep 11, 2015, at 20:01, Michael Torrie wrote: >> The secret to understanding the global keyword is to understand how >> Python namespaces work. The statement "a=5" does not assign a 5 to the >> box called "a." Rather it binds the name "a" to the "5" object, which >> is immutable and called into existence by the interpreter >> implementation. > > In other words, it assigns a pointer to the "5" object [otherwise known > as "a 5"] to the box called "a". (And increments its reference count, if > you care about how the CPython garbage collector works) Yes I suppose that works. It shows the difference between Pascal's "a := 5" and Python's "a = 5". So long as it's not just a pointer we're talking about here; it's a counted reference. I think I prefer the word "reference" to "pointer" in this case. The word, pointer has certain connotations that come from C. Certainly in the implementation you would probably use pointers. But we don't really need a full physical memory abstraction to understand names and how they are bound (made to refer) to objects. In fact it might be more useful to forget about the underlying mechanisms in the interpreter. And it's useful to think about namespaces because then we can understand what happens when python sees a variable in an expression. In any case, we're not overwriting any values in Python assignments.