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


Groups > comp.lang.python > #40045

Re: python 3 problem: how to convert an extension method into a class Method

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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; 'none,': 0.05; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:into': 0.09; 'subject:method': 0.09; 'utf8': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:python': 0.11; 'extension': 0.13; "'from": 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'bytes': 0.17; 'instance': 0.17; 'refers': 0.17; 'unicode': 0.17; 'math': 0.20; 'import': 0.21; 'subject:problem': 0.22; 'cc:2**0': 0.23; 'class.': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; '0.5': 0.29; 'class': 0.29; 'to:addr:python-list': 0.33; 'received:org': 0.36; 'wanted': 0.36; 'method': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'here': 0.65; 'analysis': 0.70; 'received:109': 0.74; 'otten': 0.84; 'sfxlen:4': 0.84; 'pfxlen:big': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robin Becker <robin@reportlab.com>
Subject Re: python 3 problem: how to convert an extension method into a class Method
Date Wed, 27 Feb 2013 10:36:27 +0000
References <512CEF0C.3020906@chamonix.reportlab.co.uk> <kgivf6$ojl$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-Gmane-NNTP-Posting-Host 109.174.168.73
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130215 Thunderbird/17.0.3
In-Reply-To <kgivf6$ojl$1@ger.gmane.org>
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 <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2602.1361961396.2939.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361961396 news.xs4all.nl 6904 [2001:888:2000:d::a6]:51596
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:40045

Show key headers only | View raw


On 26/02/2013 18:38, Peter Otten wrote:
> Robin Becker wrote:
...........3:
>
> $ python -m timeit -s 'from new import instancemethod
>> from math import sqrt
>> class A(int): pass
>> A.m = instancemethod(sqrt, None, A)
>> a = A(42)
>> ' 'a.m()'
> 1000000 loops, best of 3: 0.5 usec per loop
> $ python -m timeit -s 'from math import sqrt
>> class A(int):
>>      def m(self):
>>          return sqrt(self)
>> a = A(42)
>> ' 'a.m()'
> 1000000 loops, best of 3: 0.473 usec per loop
>
>
this analysis might be relevant if I wanted to use sqrt. However, in my case the 
method takes



                       py  C
utf8 bytes            50  20 usec
unicode               39  15

here py refers to a native python method and C  to the extension method after 
adding to the class. Both are called via an instance of the class.
-- 
Robin Becker

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


Thread

Re: python 3 problem: how to convert an extension method into a class Method Robin Becker <robin@reportlab.com> - 2013-02-27 10:36 +0000

csiph-web