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


Groups > comp.lang.python > #99077

Re: Why doesn't this method have access to its "self" argument?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Why doesn't this method have access to its "self" argument?
Date Thu, 19 Nov 2015 19:00:15 +0100
Organization None
Lines 36
Message-ID <mailman.474.1447956061.16136.python-list@python.org> (permalink)
References <db6apoFgvjlU1@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Trace news.uni-berlin.de QxFWmRVn2R0cKploIwOAMw7sJ/BEHlvuYeqIE/nCw29g==
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; 'elegant': 0.07; 'wrapper': 0.07; 'instance.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'subject:method': 0.09; 'python': 0.10; 'def': 0.13; 'a()': 0.16; 'a(object):': 0.16; 'argument.': 0.16; 'descriptors.': 0.16; 'example)': 0.16; 'invokes': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'subject:access': 0.16; 'value:': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'pointer': 0.18; 'function,': 0.22; 'pass': 0.22; 'passing': 0.23; 'written': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'header:X -Complaints-To:1': 0.26; 'separate': 0.27; 'function': 0.28; 'seemingly': 0.29; 'workaround': 0.29; 'somebody': 0.30; "i'd": 0.31; 'maybe': 0.33; 'class': 0.33; 'instance': 0.35; 'robert': 0.35; 'but': 0.36; 'subject:" ': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'why': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'latest': 0.64; 'python-list': 0.66; 'receive': 0.71; 'subject:have': 0.80; 'hood': 0.84; 'subject:its': 0.84; 'subject:self': 0.84; 'subject:this': 0.85
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd8a8e.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
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>
Xref csiph.com comp.lang.python:99077

Show key headers only | View raw


Robert Latest via Python-list wrote:

> I found a workaround using a wrapper method which calls a C function,
> passing the instance as a separate argument. It works, and I cannot see
> any disadvantage. It's just not as elegant as I'd like it to be, and I
> don't understand WHY the C "method" doesn't receive a pointer to the
> Python instance. Maybe somebody can clarify.

I don't know much about the C-implementation side, but functions written in 
Python are also descriptors. Given

def f(self): pass

class A(object):
    m = f
    c = abs
    v = 42

a = A()

a seemingly simple attribute access

m = a.m      # m is now a bound method

invokes f.__get__(a, A) under the hood while

m = a.c
assert m is abs

just returns the function (abs in the example) the same way it returns any 
other value:

v = a.v
assert v == 42

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


Thread

Why doesn't this method have access to its "self" argument? Robert Latest <boblatest@yahoo.com> - 2015-11-19 16:13 +0000
  Re: Why doesn't this method have access to its "self" argument? Chris Angelico <rosuav@gmail.com> - 2015-11-20 04:34 +1100
  Re: Why doesn't this method have access to its "self" argument? Peter Otten <__peter__@web.de> - 2015-11-19 19:00 +0100
  Re: Why doesn't this method have access to its "self" argument? dieter <dieter@handshake.de> - 2015-11-20 08:18 +0100

csiph-web