Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17083

Re: Overriding a global

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
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; 'value,': 0.04; 'cpython': 0.05; 'compiler': 0.07; 'deliberately': 0.09; 'global,': 0.09; 'def': 0.13; "'as'": 0.16; 'general.': 0.16; 'scope.': 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; 'language': 0.17; 'wrote:': 0.18; 'seems': 0.20; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'dec': 0.22; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; '+0100,': 0.23; 'globally': 0.23; 'cc:2**0': 0.24; 'changes,': 0.24; 'function': 0.27; 'code,': 0.27; 'asking': 0.28; 'true,': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'skip:g 40': 0.30; 'propose': 0.32; 'objects': 0.32; 'idea': 0.32; 'header:User- Agent:1': 0.33; 'too': 0.34; 'presence': 0.36; 'but': 0.37; 'received:192': 0.37; 'think': 0.37; 'using': 0.38; 'steven': 0.38; "it's": 0.40; 'received:192.168': 0.40; '2011': 0.61; 'making': 0.67; 'care': 0.71; 'header:Reply-To:1': 0.71; 'reply- to:no real name:2**0': 0.72; 'trick.': 0.84; 'unique.': 0.84; 'technique': 0.93
Date Mon, 12 Dec 2011 16:43:54 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: Overriding a global
References <roy-B236C9.15475310122011@news.panix.com> <mailman.3500.1323551240.27778.python-list@python.org> <roy-EC9997.16105310122011@news.panix.com> <mailman.3542.1323688423.27778.python-list@python.org> <4ee671f6$0$29979$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <4ee671f6$0$29979$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:39j6Cj6usZ3/71UCfmDmsXsmAa3JSmpxcwzNaMUcgHZ YQwsbdfXuo8D1ZNIO++yZN31F0f3G46Rc3AiXqIVUPiM/cl/L9 fIpD7bONyHK2BUuMTm6ghpV9gcUexqOpg/uGYsy0Hdzp0m4NUA 3PY/MWuSeeeLC72Y7ZOG0nWqr2n7dc7PQ8bLsRKxrzFLYguOf+ et1XbXei5OWpIhD+DCnz5TMduzT28oM4R5Ngp06tyqgij/5ZXM pTxKIpH/1JiGcjnrSRqyb+ODwb6t1tKQIQKzKtoUxMSDeZXfWk Ot3hjq1H4tpUAfQC4qpNGEAoOQMY2QmhtKYHNC87jN59VpFPaM XkGw+tRY12MErYQjxQps=
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
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.3569.1323726243.27778.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323726243 news.xs4all.nl 6875 [2001:888:2000:d::a6]:33193
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17083

Show key headers only | View raw


On 12/12/2011 04:28 PM, 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.
>
>
True, but in this code, the function is trying to both use the global 
value, but also a local that deliberately has the same name, but a 
different meaning and "value".  The CPython compiler doesn't make this 
easy, and I think the globals() technique is unnecessarily obscure, as 
is the default-argument trick.

If a function knows of the presence of a global, it's not asking too 
much for it to not re-use the same name in local scope.

Since it seems to be in vogue to propose language changes, how about a 
new place for 'as' ?
def myfunc():
      global logger as g_logger
      logger = g_logger.debug('stuff').getChild('function')

-- 

DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Overriding a global Roy Smith <roy@panix.com> - 2011-12-10 15:47 -0500
  Re: Overriding a global MRAB <python@mrabarnett.plus.com> - 2011-12-10 21:07 +0000
    Re: Overriding a global Roy Smith <roy@panix.com> - 2011-12-10 16:10 -0500
      Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-12 12:13 +0100
        Re: Overriding a global Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-12 21:28 +0000
          Re: Overriding a global Dave Angel <d@davea.name> - 2011-12-12 16:43 -0500
            Re: Overriding a global Ben Finney <ben+python@benfinney.id.au> - 2011-12-13 09:27 +1100
              Re: Overriding a global Dave Angel <d@davea.name> - 2011-12-12 20:46 -0500
              Re: Overriding a global Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-13 01:48 +0000
              Re: Overriding a global Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-12 22:50 -0700
              Re: Overriding a global Joshua Landau <joshua.landau.ws@gmail.com> - 2011-12-13 08:34 +0000
              Re: Overriding a global Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-13 12:34 -0700
              Re: Overriding a global Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-13 12:54 -0700
          Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-13 10:54 +0100
            Re: Overriding a global Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-13 11:15 +0000
              Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-13 14:30 +0100
              Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 11:14 +0100
              Re: Overriding a global Chris Angelico <rosuav@gmail.com> - 2011-12-14 21:32 +1100
              Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 13:05 +0100
                Re: Overriding a global Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-12-14 12:53 +0000
                Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 14:35 +0100
              Re: Overriding a global Chris Angelico <rosuav@gmail.com> - 2011-12-14 23:21 +1100
              Re: Overriding a global Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-12-14 18:06 +0100
  Re: Overriding a global Terry Reedy <tjreedy@udel.edu> - 2011-12-10 19:14 -0500
  Re: Overriding a global Terry Reedy <tjreedy@udel.edu> - 2011-12-10 19:19 -0500
  Re: Overriding a global Peter Otten <__peter__@web.de> - 2011-12-11 09:14 +0100
  Re: Overriding a global Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2011-12-13 10:15 +0100

csiph-web