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


Groups > comp.lang.python > #40004 > unrolled thread

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

Started byEthan Furman <ethan@stoneleaf.us>
First post2013-02-26 12:19 -0800
Last post2013-02-26 12:19 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: python 3 problem: how to convert an extension method into a class Method Ethan Furman <ethan@stoneleaf.us> - 2013-02-26 12:19 -0800

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

FromEthan Furman <ethan@stoneleaf.us>
Date2013-02-26 12:19 -0800
SubjectRe: python 3 problem: how to convert an extension method into a class Method
Message-ID<mailman.2574.1361911052.2939.python-list@python.org>
On 02/26/2013 09:21 AM, Robin Becker wrote:
> In python 2 I was able to improve speed of reportlab using a C extension to optimize some heavily used methods.
>
> so I was able to do this
>
>
> class A:
>      .....
>      def method(self,...):
>         ....
>
>
> try:
>      from extension import c_method
>      import new
>      A.method = new.instancemethod(c_method,None,A)
> except:
>      pass
>
> and if the try succeeds our method is bound as a class method ie is unbound and works fine when I call it.
>
> In python 3 this doesn't seem to work at all. In fact the new module is gone. The types.MethodType stuff doesn't seem to
> work.
>
> Is there a way in Python 3.3 to make this happen? This particular method is short, but is called many times so adding
> python wrapping layers is not a good way forward.

Dumb question, but have you tried just assigning it?  In Py3 methods are just normal functions...

8<----------------------
   class A():
       pass

   A.method = c_method
8<----------------------

--
~Ethan~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web