Setting an attribute on a Python object from C

G. Sumner Hayes SumnerH at fool.com
Fri Mar 9 10:25:27 EST 2001


Hi,

I'm working on a Python extension in C and I've reached a point I can't
get past.  How do I create an attribute on an object from C?
PyObject_SetAttrString (or _SetAttr) doesn't seem to work for this.
Here's what I'm doing (implementing a Python DB 2.0 driver for Microsoft
SQL server):

self=PyObject_NEW(mssql_cursor, &mssql_cursor_type);
v=PyInt_FromLong(i);
rv=PyObject_SetAttrString((PyObject*) self, "rowcount", Py_None);

But rv comes back as -1.  Do I need to declare room in the mssql_cursor
struct and somehow declare the rowcount attribute to point at that?

Sumner





More information about the Python-list mailing list