Setting an attribute on a Python object from C

Steve Holden sholden at
Sat Mar 10 00:17:41 CET 2001

"G. Sumner Hayes" <SumnerH at> wrote in message
news:mailman.984151691.9715.python-list at
> 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?
Are you aware of mxODBC? Without wishing to steal your thunder, it's a
pretty good ODBC for (SQL Server, Access, ...)


More information about the Python-list mailing list