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. Advertisements

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:
    574
    Default User
    Aug 2, 2004
  2. Praveen, Tayal (IE10)
    Replies:
    0
    Views:
    586
    Praveen, Tayal (IE10)
    Mar 17, 2005
  3. John123

    Profiling API or Membership API

    John123, Oct 20, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    515
    John123
    Oct 20, 2006
  4. 7stud
    Replies:
    11
    Views:
    1,071
    Dennis Lee Bieber
    Mar 20, 2007
  5. George2

    platform specific API or C standard API

    George2, Nov 12, 2007, in forum: C Programming
    Replies:
    13
    Views:
    988
    Tor Rustad
    Nov 13, 2007
  6. Timothy Grant
    Replies:
    5
    Views:
    637
    Timothy Grant
    Aug 6, 2008
  7. mike
    Replies:
    1
    Views:
    441
    Mark Space
    Mar 3, 2009
  8. Krithika San
    Replies:
    3
    Views:
    595
    Marnen Laibow-Koser
    Nov 14, 2009
Loading...