C api: how to create objects?

Discussion in 'Python' started by Heikki Salo, Apr 26, 2004.

  1. Heikki Salo

    Heikki Salo Guest

    I bumbed into a seemingly trivial problem: in my C extension I want to
    create some very basic Python objects (no methods or attributes) and then
    add all the needed attributes according to given information.

    How can I do this!? I have tried to make new instances from PyObject with
    PyObject_New() and with some other functions as well, but the only result is
    that the application comes crashing down. I guess that I am doing something
    very wrong.

    This Python-code explains what I am trying to do:

    class Generic:
    pass

    data = getData()
    new_generic = Generic()

    if "color" in data:
    new_generic.color_value = data["color"]
    elif "position" in data:
    ...
    Heikki Salo, Apr 26, 2004
    #1
    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. Shlomo Anglister
    Replies:
    1
    Views:
    399
    Default User
    Aug 2, 2004
  2. Praveen, Tayal (IE10)
    Replies:
    0
    Views:
    361
    Praveen, Tayal (IE10)
    Mar 17, 2005
  3. 7stud
    Replies:
    11
    Views:
    669
    Dennis Lee Bieber
    Mar 20, 2007
  4. mike
    Replies:
    1
    Views:
    311
    Mark Space
    Mar 3, 2009
  5. Krithika San
    Replies:
    3
    Views:
    323
    Marnen Laibow-Koser
    Nov 14, 2009
Loading...

Share This Page