Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'global,': 0.09; 'module)': 0.09; 'python': 0.10; 'def': 0.13; '(more': 0.16; 'advantage.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'latter,': 0.16; 'statement!': 0.16; 'worse.': 0.16; 'wrote:': 0.16; 'app': 0.16; 'fix': 0.21; 'java': 0.22; 'trying': 0.22; "python's": 0.23; 'this:': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'character': 0.29; 'that.': 0.30; 'another': 0.32; 'skip:_ 10': 0.32; 'message- id:@gmail.com': 0.34; 'languages': 0.34; 'that,': 0.34; 'something': 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'one,': 0.37; 'things': 0.38; 'anything': 0.38; 'does': 0.39; 'enough': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'easy': 0.60; 'him': 0.60; 'charset:windows-1252': 0.62; 'our': 0.64; 'battle': 0.84; 'esteemed': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Fri, 04 Sep 2015 19:42:21 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Python handles globals badly. References: <58e0d1b5-a7ca-4811-9926-fba1b7ede83f@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441417841 news.xs4all.nl 23808 [2001:888:2000:d::a6]:36205 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96037 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 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.