C api: how to create objects?

H

Heikki Salo

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top