Python/C API and setattr
Thomas S. Strinnhed
thstr at serop.abb.se
Wed Jun 9 10:37:42 EDT 1999
Hi again
Gee, you guys are so fast :-)
Moshe Zadka wrote:
> > Could there be something about this line;
> > self->value = (int)PyInt_AsLong(v);
> > (self->value is an int and v is PyObject*)
>
> Err......defensive programing says: check it is a Python int before
> converting (there's a PyInt_Check() function somewhere -- check with
> the docs).
Ok, you're right about that one, but PyInt_AsLong() *does* deliver and
int and the value *is* correct.
> Are you sure there shouldn't be a Py_ParseTuple(..) function somewhere
> too?
No I'm not, but my Objects\xxobject.c inspiration doesn't use one
so I thought I'd get away without one.
> What exactly "doesn't fly?" (i.e., what error do you get?)
>>> c.value = 23
Traceback (innermost last):
File "<stdin>", line 1, in ?
SystemError: error return without exception set
>>> c.value
23
This is the error I get and according to Gordon McMillan this
is (just like you pointed out) related to the fact that C
returns NULL to Python. But the value is, as you can see
from the printout, just what I wanted.
And I now always return a Py_None (carefully incref'd),
but the error remains :-/
Many Thanks
-- Thomas S. Strinnhed, thstr at serop.abb.se
More information about the Python-list
mailing list