Re: How to modify object attribute by python C API

2007-01-12 Thread Huayang Xia
Thanks for the replies. For the checking, I found we have to spend a lot of codes to check the Python API's results. That is a pain. Is it reasonable to ignore the result check of APIs like PyString_FromString and PyString_AsString which will fail only when out of memory. Unfortunately there is no

Re: How to modify object attribute by python C API

2007-01-12 Thread Ben Sizer
Huayang Xia wrote: > PyObject* py_obj_attr1 = PyObject_GetAttrString(obj, "attr1"); > PyObject_SetAttrString(py_obj_attr1, "attr2", > PyString_FromString("a")); > Py_DECREF(py_obj_attr1); > > The object py_obj_attr1 is said to be a "New reference". It's > confusing, does it refer to th

Re: How to modify object attribute by python C API

2007-01-11 Thread Gabriel Genellina
At Thursday 11/1/2007 18:37, Huayang Xia wrote: I get a python object by running a class' constructor. Then I need to modify the instance's attribute just like obj.attr1.attr2 = 'a' if in python's term. PyObject* py_obj_attr1 = PyObject_GetAttrString(obj, "attr1"); PyObject_SetAttrStrin

How to modify object attribute by python C API

2007-01-11 Thread Huayang Xia
I get a python object by running a class' constructor. Then I need to modify the instance's attribute just like obj.attr1.attr2 = 'a' if in python's term. PyObject* py_obj_attr1 = PyObject_GetAttrString(obj, "attr1"); PyObject_SetAttrString(py_obj_attr1, "attr2", PyString_FromString("a"));