Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '16,': 0.03; 'attributes': 0.07; "object's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'attribute,': 0.16; 'itself).': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sebastian': 0.16; 'surprising': 0.16; 'wrote:': 0.16; 'meant': 0.22; "aren't": 0.22; 'class,': 0.22; 'referring': 0.22; 'am,': 0.23; 'code.': 0.23; '2015': 0.23; 'normally': 0.23; 'unlike': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; "i'm": 0.29; 'mind,': 0.29; 'sense': 0.29; 'function': 0.30; 'code': 0.31; 'belong': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'surprised': 0.33; 'subject:?': 0.34; 'changed': 0.35; 'wrong': 0.35; 'to:addr:python-list': 0.35; 'false': 0.35; 'instance': 0.35; 'subject:: ': 0.37; 'tue,': 0.38; 'received:org': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'subject:the': 0.40; 'easy': 0.60; 'your': 0.60; 'simple': 0.61; 'within': 0.64; 'direct': 0.70; 'touch': 0.71; 'obvious': 0.72; '(they': 0.84; '_o__)': 0.84; 'assertion.': 0.84; 'received:125': 0.84; 'musical': 0.91; 'subject:Set': 0.91; 'instrument': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Set a flag on the function or a global? Date: Tue, 16 Jun 2015 10:20:38 +1000 References: <557f6676$0$21718$c3e8da3@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:Un0WebISFYP8B8BHn1Di4fp8bK0= 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1434414054 news.xs4all.nl 2821 [2001:888:2000:d::a6]:53024 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 4368 X-Received-Body-CRC: 1045837801 Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone01.am1.xlned.com!bcyclone01.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:92647 Chris Angelico writes: > On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano > wrote: > > 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). 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. In what sense do they “belong to” the function itself *more than* to outside callers? -- \ “It's easy to play any musical instrument: all you have to do | `\ is touch the right key at the right time and the instrument | _o__) will play itself.” —Johann Sebastian Bach | Ben Finney