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


Groups > comp.lang.python > #92651

Re: Set a flag on the function or a global?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2b.news.xs4all.nl!xs4all!post.news.xs4all.nl!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.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; '16,': 0.03; 'attributes': 0.07; "object's": 0.09; 'cc:addr:python-list': 0.10; 'interpreter': 0.15; 'attribute,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'itself).': 0.16; 'surprising': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'module,': 0.18; 'odd': 0.18; 'work,': 0.21; 'cc:2**0': 0.21; 'cc:addr:python.org': 0.21; 'meant': 0.22; "aren't": 0.22; 'class,': 0.22; 'referring': 0.22; 'am,': 0.23; 'code.': 0.23; 'defined': 0.23; '2015': 0.23; 'module': 0.23; 'normally': 0.23; 'unlike': 0.23; "i've": 0.24; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'message-id:@mail.gmail.com': 0.28; "i'm": 0.29; 'mind,': 0.29; 'sense': 0.29; 'function': 0.30; 'code': 0.31; 'usually': 0.33; 'belong': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'surprised': 0.33; 'subject:?': 0.34; 'received:google.com': 0.34; 'changed': 0.35; 'wrong': 0.35; 'false': 0.35; 'instance': 0.35; 'but': 0.36; 'being': 0.36; 'created': 0.36; 'should': 0.37; 'setting': 0.37; 'subject:: ': 0.37; 'tue,': 0.38; 'does': 0.39; 'subject:the': 0.40; 'easy': 0.60; 'your': 0.60; 'simple': 0.61; 'skip:u 10': 0.62; 'within': 0.64; 'different': 0.64; 'direct': 0.70; 'obvious': 0.72; '(they': 0.84; 'assertion.': 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:content-transfer-encoding; bh=S1CkBtwEM+5KY/4Peihc2qcADZ8c4fijHgqrXLQdjCQ=; b=TugHQa/GkjtN7c8qCqkL2//0aXlxG/TynzsBUyWaXjuOFatXpJarqrypgW6+k4NQI0 4OI9cPgsYylRnqsWQXJ7FjFWzXuO5+ymgueIEgtzkD4m1Xm92JPNt3a6RZ33KuhgV9Iz bSydN33BXtrciBoqERzvYjxSbni97+3UC5KBZVDI3LG3cezIYHY8aZ187LRhaxHcwlXG M+WQTXP1rHQjv4siXZna/y+3ys6X+c5X4c6J3sVujNO8RkVtaJxwOkJWaHAZjIAP59y2 /iuA/4gx5ez8OpYyo8xPooy7S0sw7Yd2VZkMK16mGrZrwD3nAdOPMdkCvlNw81iYc9J4 eWPw==
MIME-Version 1.0
X-Received by 10.107.160.141 with SMTP id j135mr38488328ioe.43.1434414761369; Mon, 15 Jun 2015 17:32:41 -0700 (PDT)
In-Reply-To <85oakgtsfd.fsf@benfinney.id.au>
References <557f6676$0$21718$c3e8da3@news.astraweb.com> <CAPTjJmr9r7Ev2Dw3+fY=mzOF3dz5TaXWX07TFH9R0u7JVxrzCg@mail.gmail.com> <85oakgtsfd.fsf@benfinney.id.au>
Date Tue, 16 Jun 2015 10:32:41 +1000
Subject Re: Set a flag on the function or a global?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.493.1434414769.13271.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1434414769 news.xs4all.nl 2969 [2001:888:2000:d::a6]:37437
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:92651

Show key headers only | View raw


On Tue, Jun 16, 2015 at 10:20 AM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Chris Angelico <rosuav@gmail.com> writes:
>
>> On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano
>> <steve+comp.lang.python@pearwood.info> 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?

Custom function attributes (as in, those not set by the interpreter
itself) are pretty rare, but I've usually seen them only being defined
by the module that created them. Setting that kind of attribute
externally, from a different module, seems odd - and undiscoverable.
But for interactive work, that should be fine.

ChrisA

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


Thread

Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-15 23:57 +0000
  Re: Set a flag on the function or a global? Chris Angelico <rosuav@gmail.com> - 2015-06-16 10:07 +1000
  Re: Set a flag on the function or a global? Ethan Furman <ethan@stoneleaf.us> - 2015-06-15 17:19 -0700
  Re: Set a flag on the function or a global? Ben Finney <ben+python@benfinney.id.au> - 2015-06-16 10:20 +1000
    Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 19:07 +1000
  Re: Set a flag on the function or a global? Ethan Furman <ethan@stoneleaf.us> - 2015-06-15 17:21 -0700
  Re: Set a flag on the function or a global? sohcahtoa82@gmail.com - 2015-06-15 17:24 -0700
    Re: Set a flag on the function or a global? MRAB <python@mrabarnett.plus.com> - 2015-06-16 01:35 +0100
      Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 18:18 +1000
        Re: Set a flag on the function or a global? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-06-16 13:45 +0100
          Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 22:46 +0000
        Re: Set a flag on the function or a global? Cameron Simpson <cs@zip.com.au> - 2015-06-17 09:51 +1000
          Re: Set a flag on the function or a global? Steven D'Aprano <steve@pearwood.info> - 2015-06-18 00:59 +1000
            Re: Set a flag on the function or a global? Laura Creighton <lac@openend.se> - 2015-06-17 17:06 +0200
              Re: Set a flag on the function or a global? Steven D'Aprano <steve@pearwood.info> - 2015-06-18 01:55 +1000
                Documenting a function signature (was: Set a flag on the function or a global?) Ben Finney <ben+python@benfinney.id.au> - 2015-06-18 10:04 +1000
                Re: Documenting a function signature (was: Set a flag on the function or a global?) Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-17 18:10 -0600
                Re: Documenting a function signature (was: Set a flag on the function or a global?) Chris Angelico <rosuav@gmail.com> - 2015-06-18 10:14 +1000
                Re: Documenting a function signature (was: Set a flag on the function or a global?) random832@fastmail.us - 2015-06-18 08:37 -0400
                Re: Documenting a function signature (was: Set a flag on the function or a global?) Laura Creighton <lac@openend.se> - 2015-06-18 23:38 +0200
                Re: Documenting a function signature Ben Finney <ben+python@benfinney.id.au> - 2015-06-19 10:41 +1000
  Re: Set a flag on the function or a global? Ron Adam <ron3200@gmail.com> - 2015-06-15 20:24 -0400
    Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 19:15 +1000
      Re: Set a flag on the function or a global? Ron Adam <ron3200@gmail.com> - 2015-06-16 07:02 -0400
  Re: Set a flag on the function or a global? Chris Angelico <rosuav@gmail.com> - 2015-06-16 10:32 +1000
  Re: Set a flag on the function or a global? Paul Rubin <no.email@nospam.invalid> - 2015-06-15 17:37 -0700
    Re: Set a flag on the function or a global? Ethan Furman <ethan@stoneleaf.us> - 2015-06-15 17:53 -0700
      Re: Set a flag on the function or a global? Paul Rubin <no.email@nospam.invalid> - 2015-06-15 19:04 -0700
    Re: Set a flag on the function or a global? MRAB <python@mrabarnett.plus.com> - 2015-06-16 02:15 +0100
    Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 18:30 +1000
  Re: Set a flag on the function or a global? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-16 07:06 +0100
    Re: Set a flag on the function or a global? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-16 19:28 +1000
  Re: Set a flag on the function or a global? Jonas Wielicki <jonas@wielicki.name> - 2015-06-16 12:00 +0200
  Re: Set a flag on the function or a global? Michael Torrie <torriem@gmail.com> - 2015-06-16 07:44 -0600
  Re: Set a flag on the function or a global? Michael Torrie <torriem@gmail.com> - 2015-06-16 07:56 -0600
  Re: Set a flag on the function or a global? Peter Otten <__peter__@web.de> - 2015-06-16 15:59 +0200
  Re: Set a flag on the function or a global? Ethan Furman <ethan@stoneleaf.us> - 2015-06-16 07:57 -0700

csiph-web