no unbound methods in py3k
Thomas Heller
theller at python.net
Thu Oct 9 15:36:03 EDT 2008
Terry Reedy schrieb:
> Thomas Heller wrote:
>> Christian Heimes schrieb:
>>> I've written PyInstanceMethod_Type for this use case. It's not (yet)
>>> available for Python code.>> Oh, wait - there's ctypes:
>>
>> Python 3.0rc1 (r30rc1:66507, Sep 18 2008, 14:47:08) [MSC v.1500 32 bit (Intel)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> from ctypes import *
>>>>> pythonapi.PyInstanceMethod_New.restype = py_object
>>>>> pythonapi.PyInstanceMethod_New.argtypes = [py_object]
>>>>> instancemethod = pythonapi.PyInstanceMethod_New
>>>>>
>>>>> class Example:
>> ... pass
>> ...
>>>>> Example.id = instancemethod(id)
>>>>>
>>>>> x = Example()
>>>>> x.id()
>> 12597296
>>>>> id(x)
>> 12597296
>
> A pyCapi module that exposed via ctypes useful C functions not otherwise
> accessible, with predefinition of restype and argtypes and anything else
> needed, might make a nice addition to PyPI if not the stdlib. You have
> done two here and I believe others have posted others.
Well, Lenard Lindstrom has some time ago contributed a module like that
which is available in the (more or less unmaintained) ctypeslib project:
http://svn.python.org/projects/ctypes/trunk/ctypeslib/ctypeslib/contrib/pythonhdr.py
However, it was probably more meant to provide a complete Python C api,
instead of concentrating on stuff not available to Python otherwise.
Thomas
More information about the Python-list
mailing list