Question to python C API

Stefan Behnel stefan_ml at behnel.de
Wed Apr 15 18:56:17 CEST 2009


Andreas Otto wrote:
>   I have the following question ...
> 
>   I write a custom "*.init" method and expect a variable number or arguments

What's a "*.init" method? Do you mean SomeType.__init__() ?


>   This are my questions:
> 
>   1.    I need something like a for loop to analyse this arguments
>         For now I try the "PyArg_ParseTupleAndKeywords" but i missing somehing 
>         like an Object-Array return value as "format" ....
> 
>   2.    can i combine variable args with keywords ?
>         because it will fit into my spec to use both together
> 
>   3.    I want to retrieve a bool object as int value, where is a format "O"
>         and "O!" for a type object .... HOWTO put the type into the function from
>         above

You might want to take a look at Cython. It allows you to write C
extensions in a Python-like language, so all of the above become trivial, e.g.

    cdef class MyExtensionType(object):
        def __init__(self, bint some_c_bool):
             print type(self) is MyExtensionType
             print some_c_bool == 1

Cython will translate this to efficient C code for you.

http://cython.org/

Stefan



More information about the Python-list mailing list