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


Groups > comp.lang.python > #96038

Re: Python handles globals badly.

Path csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <rosuav@gmail.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; 'subject:Python': 0.05; 'cc:addr:python-list': 0.09; 'assigning': 0.09; 'global,': 0.09; 'module)': 0.09; 'python': 0.10; 'def': 0.13; '"write': 0.16; '(more': 0.16; '11:42': 0.16; 'advantage.': 0.16; 'dotted': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'globals.': 0.16; 'latter,': 0.16; 'statement!': 0.16; 'worse.': 0.16; 'wrote:': 0.16; 'app': 0.16; 'programmer': 0.18; 'language': 0.19; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; 'java': 0.22; 'sep': 0.22; 'trying': 0.22; 'am,': 0.23; "python's": 0.23; 'sat,': 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.27; 'character': 0.29; 'that.': 0.30; 'code': 0.30; 'another': 0.32; 'skip:_ 10': 0.32; 'michael': 0.33; 'languages': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'behind': 0.35; 'something': 0.35; 'level': 0.35; 'but': 0.36; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'one,': 0.37; 'things': 0.38; 'anything': 0.38; 'does': 0.39; 'enough': 0.39; 'still': 0.40; 'easy': 0.60; 'him': 0.60; 'your': 0.60; 'our': 0.64; 'concerns': 0.66; 'battle': 0.84; 'chrisa': 0.84; 'to:none': 0.91; 'esteemed': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=cqzWzqdD6zHlcEyRYthe2tWPltm/wY9dWBMgvVOO8mM=; b=sk+K3C6I2ovND0oPnmrrvFNZodz3OKXhyUlITzuciKoaN8Az/Xyjv/r1jdskJURzIO q4yTXPFOMBalzRcz7oyUiP/sqLu03Hk/yZkukyeDtj2T7gaQP2j8pwtRdomUVHhYdSE/ JOvvMbEkPqxy+sMKi87XZCiZQnGo+emkWgwK57ZII0B53gcUynM9IVh63ukSkZ1mjT0w 4b+S4o12sQkpr8m9TpTbMnb+jmyCVcAAPXx9k81/zZtYlpAc7UFBbRtVsM3+7BR+kRC3 PJQwSzIiYH2n5pnfC+C6MMD89vF3ETu9mmJp1d/kbkLtZX/t29jjTUAtKsFckoMFKcX5 l2jA==
MIME-Version 1.0
X-Received by 10.50.98.7 with SMTP id ee7mr12694042igb.13.1441418071058; Fri, 04 Sep 2015 18:54:31 -0700 (PDT)
In-Reply-To <55EA487D.2010807@gmail.com>
References <c3363$547e74fe$5419aafe$24179@news.ziggo.nl> <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> <CAPTjJmpkry3qBL9ntf4gUsE-aDGLooHqViMBW=ZNcK2Lb9e9nA@mail.gmail.com> <55EA487D.2010807@gmail.com>
Date Sat, 5 Sep 2015 11:54:30 +1000
Subject Re: Python handles globals badly.
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.155.1441418073.8327.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441418073 news.xs4all.nl 23759 [2001:888:2000:d::a6]:38883
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5110
X-Received-Body-CRC 97449022
Xref csiph.com comp.lang.python:96038

Show key headers only | View raw


On Sat, Sep 5, 2015 at 11:42 AM, Michael Torrie <torriem@gmail.com> wrote:
> On 09/04/2015 06:27 PM, Chris Angelico wrote:
>> If you want the first one, well, there are languages like that, and
>> you're welcome to use those. For the latter, it's easy enough to do
>> something like this:
>>
>> import types
>> _g = types.SimpleNamespace()
>>
>> def accumulate(x):
>>     _g.accum += x
>>     return _g.accum
>>
>> Look, Ma! No global statement!
>
> Since most of the time for me when I need a global, I need it to be an
> app global (more than just one module) and I use it to store
> configuration.  So I just use another module for that.
>
> import my_global_module as _g
>
> _g.some_setting = 5

Yeah. Comes to the same thing; if you use a dotted lookup, it's not
assigning to the global.

Of course, you still have all the other concerns about globals. You've
just buried them behind a level of indirection.

> I get the impression, thought, that our esteemed poster is still trying
> to battle the Java windmill, but in Python now and will never accept
> anything we try to tell him about the Python way.  Python does have its
> warts, but often attempts to fix the warts would just make things a lot
> worse.  So I accept them as part of Python's character and try to use
> them to my advantage.

Indeed. The key to being a good programmer is not "write your code
despite the language you're using", but "write the code in the
language you're using".

ChrisA

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


Thread

Re: Python handles globals badly. tdev@freenet.de - 2015-09-04 12:11 -0700
  Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-04 13:48 -0600
  Re: Python handles globals badly. Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-04 13:52 -0600
  Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2015-09-05 10:27 +1000
  Re: Python handles globals badly. Michael Torrie <torriem@gmail.com> - 2015-09-04 19:42 -0600
  Re: Python handles globals badly. Chris Angelico <rosuav@gmail.com> - 2015-09-05 11:54 +1000
    Program in or into (was Python handles globals badly) Rustom Mody <rustompmody@gmail.com> - 2015-09-04 20:18 -0700
      Re: Program in or into (was Python handles globals badly) Chris Angelico <rosuav@gmail.com> - 2015-09-05 13:31 +1000
      Re: Program in or into (was Python handles globals badly) Steven D'Aprano <steve@pearwood.info> - 2015-09-06 12:35 +1000
        Re: Program in or into (was Python handles globals badly) MRAB <python@mrabarnett.plus.com> - 2015-09-06 03:54 +0100
        Re: Program in or into (was Python handles globals badly) Rustom Mody <rustompmody@gmail.com> - 2015-09-05 21:35 -0700
        Re: Program in or into (was Python handles globals badly) random832@fastmail.us - 2015-09-06 01:26 -0400
          Re: Program in or into (was Python handles globals badly) wxjmfauth@gmail.com - 2015-09-06 00:42 -0700
        Re: Program in or into (was Python handles globals badly) Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-06 18:19 -0600

csiph-web