help with writing extension
Eric Hagemann
ehagemann at comcast.net
Sun Sep 29 14:11:26 EDT 2002
I have been handcrafting an extension module creating a new type
I am making use of the numeric methods (+,-,* etc)
I solved the problem of the object interating with other types by working
through the __coerce__() function and have no issue with operations like
<obj>+2 but I am getting an error on 2-<obj>.
In Beazley's book there are descriptions of functions like __radd__() when
defining a new type in python, but I cannot find reference to these
functions in C ?
I have checked the doc's (not to say that I did not miss something ;) )
What is interesting is that both <obj>+2 and 2+<obj> both end up in the
__coerce__ function. Whats even more interesting is that the arguments to
__coerce__ are in the same order for both function calls, the first argument
is <obj> the second is a PyInt. The Error I get (for 2+<obj>) is
Traceback (most recent call last):
File "C:\py_lib\test.py", line 30, in ?
print "2+d = ",2+d
TypeError: unsupported operand types for +
that occurs after the __coerce__ function finishes.
Has anybody worked through this before?
More information about the Python-list
mailing list