Creating custom Python objects from C code

Discussion in 'Python' started by Eric Frederich, Jan 5, 2011.

  1. I have read through all the documentation here:

    http://docs.python.org/extending/newtypes.html

    I have not seen any documentation anywhere else explaining how to
    create custom defined objects from C.
    I have this need to create custom objects from C and pass them as
    arguments to a function call.

    Question 1: how am I to create those objects from C code?

    The other thing I would like to know is how I can create helper
    functions in my extension so they can be created and manipulated
    easily.
    I am thinking along the lines of the built-in helper functions
    PyList_New and PyList_Append.
    Once I have an answer to question 1, the problem won't be creating the
    helper functions, but making them available from something built with
    distutils.
    To use the builtin python functions from C I need to link against
    python27.lib but when I create my own package using distutils it
    creates dll or pyd files.

    Question 2: How do I make C helper functions that are part of my
    extension available to other C projects in the same way that PyList_*,
    PyString_*, PyInt_* functions are available?
    Is it possible to have distutils make a .lib file for me?

    Thanks,
    ~Eric
     
    Eric Frederich, Jan 5, 2011
    #1
    1. Advertising

  2. Eric Frederich

    Aahz Guest

    In article <>,
    Eric Frederich <> wrote:
    >
    >I have read through all the documentation here:
    >
    > http://docs.python.org/extending/newtypes.html
    >
    >I have not seen any documentation anywhere else explaining how to
    >create custom defined objects from C. I have this need to create
    >custom objects from C and pass them as arguments to a function call.


    You should definitely investigate Cython, but if you really want to roll
    your own, look in the examples inside the Python source itself.
    --
    Aahz () <*> http://www.pythoncraft.com/

    "All problems in computer science can be solved by another level of
    indirection." --Butler Lampson
     
    Aahz, Jan 27, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ravi Ambros Wallau
    Replies:
    0
    Views:
    4,111
    Ravi Ambros Wallau
    Jun 1, 2005
  2. 7stud
    Replies:
    11
    Views:
    729
    Dennis Lee Bieber
    Mar 20, 2007
  3. =?Utf-8?B?R2hpc3Rvcw==?=

    Creating Reports with custom objects

    =?Utf-8?B?R2hpc3Rvcw==?=, Oct 24, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    406
    sloan
    Oct 24, 2007
  4. News123
    Replies:
    7
    Views:
    392
    Dave Angel
    Jun 29, 2009
  5. bizt
    Replies:
    1
    Views:
    264
    Dan Rumney
    Jun 3, 2008
Loading...

Share This Page