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


Groups > comp.lang.python > #99128

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

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From dieter <dieter@handshake.de>
Newsgroups comp.lang.python
Subject Re: Why doesn't this method have access to its "self" argument?
Date Fri, 20 Nov 2015 08:18:02 +0100
Lines 31
Message-ID <mailman.507.1448003893.16136.python-list@python.org> (permalink)
References <db6apoFgvjlU1@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace news.uni-berlin.de ybyT44LZWoxQby3QQwdJCAUxw2jqGbXPrr1H9ohOpNZw==
Cancel-Lock sha1:J2zhpUOIHKcqyq57CWcuBbWRTNE=
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.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '(so': 0.07; '*args,': 0.07; 'wrapper': 0.07; 'descriptor': 0.09; "object's": 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; '(at': 0.13; 'def': 0.13; '(but': 0.15; 'class)': 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; '(in': 0.18; 'trying': 0.22; 'import': 0.24; 'implemented': 0.24; 'header :User-Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'skip:_ 20': 0.26; 'skip:m 30': 0.27; 'least': 0.27; 'errors.': 0.27; 'function': 0.28; 'interface': 0.29; 'be:': 0.29; "i'm": 0.30; 'implement': 0.32; 'class': 0.33; 'skip:_ 30': 0.33; 'advice': 0.35; 'easiest': 0.35; 'robert': 0.35; 'problem.': 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; 'charset:us-ascii': 0.37; 'seem': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'received:de': 0.40; 'easy': 0.60; 'confirm': 0.62; 'latest': 0.64; 'python-list': 0.66; 'received:217': 0.66; 'subject:have': 0.80; '**kw)': 0.84; '**kw):': 0.84; 'subject:its': 0.84; 'subject:self': 0.84; 'subject:this': 0.85; 'severe': 0.91; 'good,': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host pd9e09e1b.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
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:99128

Show key headers only | View raw


Robert Latest via Python-list <python-list@python.org> writes:

> I'm still trying to find a simple way to implement a method (but not the
> full class) in C. Suggestions I have recived so far are good, but seem to be
> over the top for such a (seemingly) simple problem.

The C interface of Python is far from simple - and it is very easy
to make severe and difficult to analyse errors. Therefore, I confirm
an advice you already got: use "cython" (which drastically reduces
the danger of errors).

A "method" in Python is just a function which happens to get automatically
on call an additional first arguemnt: the object's reference. Apparently,
this automatism does not work for C implemented functions (at least
in Python 2). You would need to use a (so called) "descriptor" wrapper
to do this explicitely.

The easiest way (in my view), however would be:

import _my_c_implementation

class C(object):
  def my_method(self, *args, **kw):
    return _my_c_implementation.my_method(self, *args, **kw)


With a descriptor "method" (sketched above), this would become:

class C(object):
  my_method = method(_my_c_implementation.my_method)

Back to comp.lang.python | Previous | NextPrevious 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