Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '16,': 0.03; 'attributes': 0.07; 'global,': 0.09; 'cc:addr:python-list': 0.10; 'itself.': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo.': 0.16; 'interactive,': 0.16; 'itself).': 0.16; 'surprising': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'meant': 0.22; "aren't": 0.22; 'am,': 0.23; '2015': 0.23; 'module': 0.23; 'absolute': 0.23; 'normally': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'message-id:@mail.gmail.com': 0.28; 'function': 0.30; "i'd": 0.31; 'belong': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'subject:?': 0.34; 'received:google.com': 0.34; 'changed': 0.35; 'wrong': 0.35; 'false': 0.35; 'but': 0.36; 'there': 0.36; 'two': 0.37; 'subject:: ': 0.37; 'tue,': 0.38; 'skip:e 20': 0.39; 'subject:the': 0.40; 'obvious': 0.72; '(they': 0.84; 'chrisa': 0.84; 'to:none': 0.90; 'subject:Set': 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=GOJoZXbD1tmQHPOewGTaOpOsVBx3oXzmlTxjbxJtzo0=; b=ON+ARmibW+BASH4IzAzbH5RKZLehyfMkk/eiDOTK8YnwUV4ZPRsv6p2B3yhMj5Y24T D3bdrdV6Djpzn7xalQZtBF6RzRd6cJjHafkM9OSEzDNy9bGesCJwNWZ9ZitR9mBvJNYE YJYBe7Jn1WiyGfotw4P4b8707ZV5pRFsPOwJ7rShRxwb6TlLkTBQ4AQF14W7bn3umJXN /2ViBeaeYa6FWnTPVaFAIM8H/JOPH4O5cUIoYP2a8jG1XBGcQe+Kt0Zq92noxluRlT0D wN13FlLL5r1rF+JoiT74JXSEfbJxnYuMRAn/Zpr7Xboc6kAVvenSmJChA7KrxINTLQGb HUQA== MIME-Version: 1.0 X-Received: by 10.107.134.218 with SMTP id q87mr28378668ioi.27.1434413272509; Mon, 15 Jun 2015 17:07:52 -0700 (PDT) In-Reply-To: <557f6676$0$21718$c3e8da3@news.astraweb.com> References: <557f6676$0$21718$c3e8da3@news.astraweb.com> Date: Tue, 16 Jun 2015 10:07:52 +1000 Subject: Re: Set a flag on the function or a global? From: Chris Angelico Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434413280 news.xs4all.nl 2926 [2001:888:2000:d::a6]:49403 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92645 On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano wrote: > I have two ideas for this, a module-level global, or a flag set on the > function object itself. Remember that the usual way of using this will be > "from module import edir", there are two obvious ways to set the global: > > import module > module.dunders = False > > # -or- > > edir.__globals__['dunders'] = False > > > Alternatively, I can use a flag set on the function object itself: > > edir.dunders = False > For most situations, the last one is extremely surprising - attributes on functions aren't normally meant to be changed by outside callers, it always feels wrong (they belong to the function itself). But since this is interactive, I'd advise going for the absolute simplest, which this would be. Go for the function attribute IMO. ChrisA