C api: how to create objects?

Heikki Salo heikki_salo at nobulkmailplease.sci.fi
Mon Apr 26 16:03:11 EDT 2004


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






More information about the Python-list mailing list