Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'semantic': 0.07; '>>>>': 0.09; 'foo': 0.09; 'namespace': 0.09; 'def': 0.13; 'clash': 0.16; 'def.': 0.16; 'definition.': 0.16; 'general.': 0.16; 'namespace,': 0.16; 'namespace.': 0.16; 'overwriting': 0.16; 'scopes': 0.16; 'subject:Overriding': 0.16; 'subject:global': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'this:': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'cc:no real name:2**0': 0.20; "aren't": 0.21; 'dec': 0.22; 'header :In-Reply-To:1': 0.22; '+0100,': 0.23; 'found,': 0.23; 'globally': 0.23; 'cc:2**0': 0.24; 'object,': 0.24; 'code': 0.25; 'function': 0.27; 'separate': 0.28; 'assuming': 0.29; 'cc:addr:python.org': 0.29; 'confusion': 0.30; 'least': 0.30; 'point,': 0.32; 'objects': 0.32; 'tue,': 0.32; 'idea': 0.32; 'header:User-Agent:1': 0.33; 'that,': 0.33; 'there': 0.33; "we're": 0.34; 'identical': 0.34; 'issue': 0.35; "there's": 0.37; 'using': 0.38; 'steven': 0.38; 'why': 0.39; '2011': 0.61; 'your': 0.61; 'here.': 0.66; 'here:': 0.66; 'making': 0.67; 'received:62': 0.70; 'care': 0.71; 'unique.': 0.84; 'involved.': 0.91 X-IronPort-AV: E=Sophos;i="4.71,345,1320620400"; d="scan'208";a="40386" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Tue, 13 Dec 2011 14:30:42 +0100 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: Overriding a global References: <4ee671f6$0$29979$c3e8da3$5496439d@news.astraweb.com> <4ee733d4$0$29979$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <4ee733d4$0$29979$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 73 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323783056 news.xs4all.nl 6942 [2001:888:2000:d::a6]:34723 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17134 Steven D'Aprano wrote: > On Tue, 13 Dec 2011 10:54:51 +0100, Jean-Michel Pichavant wrote: > > >> Steven D'Aprano wrote: >> >>> On Mon, 12 Dec 2011 12:13:33 +0100, Jean-Michel Pichavant wrote: >>> >>> >>> >>>> Using the same name for 2 different objects is a bad idea in general. >>>> >>>> >>>> >>> We have namespaces precisely so you don't need to care about making >>> names globally unique. >>> >>> >>> >>> >> I don't get your point, namespaced names are unique, by definition. >> >> foo.aname <> bar.aname >> > > Assuming foo and bar are not names for the same object, there are at > least three namespaces here: the local namespace, where foo and bar can > be found, the foo.__dict__ namespace, and the bar.__dict__ namespace. > > > >> The OP showed a code where there was a confusion between a global name >> and a local one. There's no namespace involved. Having a local name >> identical to a global one is a bad idea, def. >> > > Of course there are namespaces involved. There is the global namespace, > and the local namespace. That's how you can have x inside a function > without it overwriting global x outside of it, because they are different > namespaces. Which is my point. > > When I write this: > > x = 1 > > def spam(): > x = 2 > > def ham(): > x = 3 > > The three x's don't clash because they are in three separate namespaces. > > I know that, why do I have the feel this is juste a semantic issue ? Aren't you/I/we confusion namespaces & scopes ? Anyway, semantic is not what we're interested in here. writing x = 1 def spam(): x = 2 is in general a bad idea. That was my point. JM