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


Groups > comp.lang.python > #17200

Re: Overriding a global

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=322fd6406=jeanmichel@sequans.com>
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; 'handler': 0.04; 'function,': 0.07; 'python': 0.08; 'namespace': 0.09; 'referenced': 0.09; 'stating': 0.09; 'def': 0.13; 'meaningful': 0.13; 'arbitrarily': 0.16; 'fruit': 0.16; 'innermost': 0.16; 'local.': 0.16; 'naming': 0.16; 'objects*': 0.16; 'resource,': 0.16; 'scopes': 0.16; 'sense...': 0.16; 'should.': 0.16; 'subject:Overriding': 0.16; 'subject:global': 0.16; 'wanted.': 0.16; 'cc:addr:python-list': 0.16; "wouldn't": 0.17; 'wed,': 0.17; 'wrote:': 0.18; 'processed': 0.18; 'cc:no real name:2**0': 0.20; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'indices': 0.23; 'loop,': 0.23; 'cc:2**0': 0.24; 'besides': 0.24; "python's": 0.24; 'code': 0.25; "i'm": 0.26; 'fact': 0.27; 'code,': 0.27; 'variable': 0.28; 'around.': 0.29; 'problem': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'chris': 0.30; 'usually': 0.31; "i've": 0.31; 'values': 0.32; 'idea': 0.32; 'header:User- Agent:1': 0.33; 'points': 0.34; 'loop': 0.34; 'nested': 0.34; 'languages': 0.35; 'variables': 0.37; 'but': 0.37; 'think': 0.37; 'doing': 0.38; 'using': 0.38; 'some': 0.38; "i'd": 0.39; 'being': 0.39; "it's": 0.40; '2011': 0.61; 'your': 0.61; 'perfect': 0.64; 'guarantee': 0.65; 'piece': 0.66; 'received:62': 0.70; '(one': 0.73; 'unnecessary': 0.73; "'foo'": 0.84; 'valid,': 0.84; 'surprise': 0.97
X-IronPort-AV E=Sophos;i="4.71,351,1320620400"; d="scan'208";a="41550"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Wed, 14 Dec 2011 13:05:19 +0100
From Jean-Michel Pichavant <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To Chris Angelico <rosuav@gmail.com>
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> <mailman.3583.1323770094.27778.python-list@python.org> <4ee733d4$0$29979$c3e8da3$5496439d@news.astraweb.com> <4EE75382.9060104@sequans.com> <CAN1F8qWRN8_ktQP1WRgPPQaG=mMV=TizcTpoRb=+1RyhznnvOg@mail.gmail.com> <4EE8771D.1050902@sequans.com> <CAPTjJmqiWTvu4pVW7i28KS1bToAnArUj24rMGBkdtzzGJFW=vQ@mail.gmail.com>
In-Reply-To <CAPTjJmqiWTvu4pVW7i28KS1bToAnArUj24rMGBkdtzzGJFW=vQ@mail.gmail.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 <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.3638.1323864323.27778.python-list@python.org> (permalink)
Lines 58
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323864323 news.xs4all.nl 6922 [2001:888:2000:d::a6]:33879
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17200

Show key headers only | View raw


Chris Angelico wrote:
> On Wed, Dec 14, 2011 at 9:14 PM, Jean-Michel Pichavant
> <jeanmichel@sequans.com> wrote:
>   
>> The problem makes little sense when using names like x or func1. Besides
>> namespace issues, naming 2 *different objects* with the same meaningful name
>> is usually a bad idea and points the fact that your names are no that
>> meaningful.
>>     
>
> So... it's a bad idea for me to use 'i' many times in my code, with
> the same name having different meanings in different places? In
> languages with infinitely-nesting scopes (one of Python's great lacks,
> imho), I've often had three different variables with the same names,
> all perfectly valid, and all doing what they should. It's not just
> loop indices - I used to have a piece of code in which 'res' was a
> MySQL resource being processed in a loop, and I had three nested
> loops. Each time I referenced 'res', it used the innermost available
> resource, which was precisely what I wanted. If I'd arbitrarily had to
> guarantee that all variable names were unique, I would have had
> completely unnecessary fiddling around.
>
> Python wouldn't let you do that with three nested 'res'es in one
> function, but you can perfectly reasonably have a global and a local.
> It makes perfect sense... which is a good reason for keeping it legal.
>
> ChrisA
>   

Bad ideas :

i = 5

def spam():
  for i,v in enumerate([1,2,3,4]):
    for i,v in enumerate(['a','b', 'c']):
      print i, v
    print i,v # bad surprise


good ideas :

# global
nameThatWillNotBeUsedlocally = 'foo'

def spam():
  for qtyIndex, quantity in enumerate([5,6,3,1]):
    for fruitIndex, fruit in enumerate(['orange', 'banana']):
      print fruitIndex, fruit
    print qtyIndex, quantity

While a lot of people still use i,j,k,v to handler values and indexes, I 
think it's a bad idea. I'm just stating an opinion from my personnal 
python experience. I know some people can successfully use the hard way.

JM

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