How to modify object attribute by python C API

Huayang Xia huayang.xia at
Thu Jan 11 22:37:08 CET 2007

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",

The object py_obj_attr1 is said to be a "New reference". It's
confusing, does it refer to the same object as "obj.attr1" in python's
term? So that the above code equals: obj.attr1.attr2 = 'a' in python's


More information about the Python-list mailing list