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


Groups > comp.lang.python > #76190

Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'assign': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:instance': 0.09; 'variable,': 0.09; 'python': 0.11; 'language,': 0.12; '__init__,': 0.16; '__lt__': 0.16; 'argument.': 0.16; 'crude': 0.16; 'itself,': 0.16; 'ought': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'set,': 0.16; 'subject: \n ': 0.16; 'subject:class': 0.16; 'subject:variable': 0.16; 'language': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'meant': 0.20; '(the': 0.22; 'aug': 0.22; 'header :User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'defined': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'am,': 0.29; '13,': 0.31; 'names.': 0.31; 'class': 0.32; 'becomes': 0.33; 'subject:from': 0.34; 'subject: (': 0.35; 'something': 0.35; 'definition': 0.35; 'but': 0.35; 'really': 0.36; 'like,': 0.36; 'method': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'name': 0.63; 'significance': 0.84; 'on?': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ned Batchelder <ned@nedbatchelder.com>
Subject Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)
Date Wed, 13 Aug 2014 08:11:05 -0400
References <CAPTjJmrVs_g4DMQzXgzng5mw7wS42pq_ceT0_Ns29RhOjLrkEQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host c-50-133-228-126.hsd1.ma.comcast.net
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
In-Reply-To <CAPTjJmrVs_g4DMQzXgzng5mw7wS42pq_ceT0_Ns29RhOjLrkEQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.12920.1407931879.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407931879 news.xs4all.nl 2899 [2001:888:2000:d::a6]:37586
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76190

Show key headers only | View raw


On 8/13/14 5:51 AM, Chris Angelico wrote:
> On Wed, Aug 13, 2014 at 7:06 PM, GregS <not@my.real.address.com> wrote:
>> When I assign the reference as a class variable, the reference has __self__
>> set, too, so I get an extra argument passed to the function.  If I assign
>> the reference as an instance variable, then __self__ is unset so no extra
>> argument.
>
> Spin-off from Greg's thread.
>
> The bound method object stores a reference to the original object (the
> thing that becomes the first argument to the target function) in
> __self__ (and the function in __func__). ISTM this ought to be _self
> (and _func), as it's intended to be private; is it really something
> that has language-level significance on par with __lt__ and so on?
>
> ChrisA
>

As I see it, dunder names are those whose meaning is defined by the 
Python language (and/or implementation?), and whose use is typically 
behind-the-scenes.  So "len" is defined by the language, but is meant to 
be front-and-center, so it has a nice name.  __init__, __lt__, and 
__self__, have meanings and uses defined by Python itself, and so are 
reasonable as dunder names.

This is a crude namespacing: Python can use any name it likes so long as 
its a dunder name, and I can use any name I like, so long as it isn't.

Yes, the definition is fuzzy.... :)

-- 
Ned Batchelder, http://nedbatchelder.com

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


Thread

Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable) Ned Batchelder <ned@nedbatchelder.com> - 2014-08-13 08:11 -0400

csiph-web