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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'function,': 0.07; 'python': 0.09; 'declarations': 0.09; 'loop.': 0.09; 'namespace': 0.09; 'def': 0.10; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'scope.': 0.16; 'wrote:': 0.17; 'variables': 0.17; 'module': 0.19; 'variable': 0.20; 'written': 0.20; 'example': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'language.': 0.27; 'in.': 0.27; 'declared': 0.29; 'objects': 0.29; 'class': 0.29; 'function': 0.30; 'johnson': 0.32; 'could': 0.32; 'problem': 0.33; 'to:addr:python-list': 0.33; 'whatever': 0.35; 'pm,': 0.35; 'received:org': 0.36; 'except': 0.36; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'does': 0.37; 'level': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'is.': 0.62; 'referred': 0.62; 'different': 0.63; 'within': 0.64; 'special': 0.73; 'unclear': 0.84; 'glance': 0.91; 'rick': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Thu, 07 Feb 2013 23:21:35 -0700 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: PyWart: Namespace asinitiy and the folly of the global statement References: <02ced8e2-5967-4ce0-b257-83c3a3fbaf8e@googlegroups.com> In-Reply-To: <02ced8e2-5967-4ce0-b257-83c3a3fbaf8e@googlegroups.com> 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: 1360304501 news.xs4all.nl 6854 [2001:888:2000:d::a6]:34188 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38415 On 02/07/2013 09:30 PM, Rick Johnson wrote: > count = 0 > class Blah: > def meth(): > for x in range(100): > count = x > > Where is count living? > > Of course in this simplistic example we can see that count is @ > module level Except that it's not after the "count=x" statement inside the for loop. That's entirely within the local scope. Names bound to objects always default to the local namespace, whatever that is. If your function referred to "count" without any assignment, then it's unclear as to which namespace it is in. It could be the class namespace, or the module namespace. But that's a problem no different than in any language. Python does differ, from, say C, where global variables can be read and written to without any special declarations in a function, though you can tell at a glance whether or not a variable is declared in the local scope.