Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed3a.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.106 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; "object's": 0.09; 'package,': 0.13; 'def': 0.14; '__init__.py': 0.16; 'attribute,': 0.16; 'foo():': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'wrote:': 0.16; 'class,': 0.22; 'referring': 0.22; 'code.': 0.23; 'module': 0.23; 'unlike': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "i'm": 0.29; 'mind,': 0.29; 'function': 0.30; 'code': 0.31; 'surprised': 0.33; 'though.': 0.33; 'subject:?': 0.34; 'message-id:@gmail.com': 0.35; 'could': 0.35; 'to:addr:python-list': 0.35; 'instance': 0.35; 'subject:: ': 0.37; 'received:org': 0.38; 'pm,': 0.39; 'test': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'sure': 0.40; 'subject:the': 0.40; 'easy': 0.60; 'your': 0.60; 'simple': 0.61; 'course': 0.64; 'within': 0.64; 'direct': 0.70; 'obvious': 0.72; 'assertion.': 0.84; 'existence.': 0.84; 'preset': 0.84; 'subject:Set': 0.91 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Tue, 16 Jun 2015 07:44:57 -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: Set a flag on the function or a global? References: <557f6676$0$21718$c3e8da3@news.astraweb.com> <85oakgtsfd.fsf@benfinney.id.au> In-Reply-To: <85oakgtsfd.fsf@benfinney.id.au> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434462309 news.xs4all.nl 2922 [2001:888:2000:d::a6]:56965 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:92676 On 06/15/2015 06:20 PM, Ben Finney wrote: > I'm surprised by your assertion. To my mind, outside callers get simple > and direct access to the attribute, whereas the code of the function > itself does not have such easy access; unlike ‘self’ for the current > instance of a class, there's no obvious name to use for referring to the > function object within the function object's own code. Of course it has access, and it's obvious and easy as well: def foo(): foo.flag = True The only thing I'm not sure of is a clean way to test for the attribute's existence. The __init__.py of a package, or the initialization code of the module could preset the attribute, though.