New Type in Extension Module Not Accessing PyNumberMethods???
doug
doug_bartholomew99 at yahoo.com
Thu Aug 9 03:07:11 EDT 2001
doug_bartholomew99 at yahoo.com (doug) wrote in message news:<e71960c5.0108081842.19435ff at posting.google.com>...
> im trying to write a python extension type which i am basically
> modeling on xxmodule.c that comes with the source. however, for the
> life of me, i cannot get the numeric operations to work (just simple
> addition and subtraction here) and i cannot see what im doing wrong.
> Isnt the following what one has to do to get numeric operations???
Ok, i have narrowed my problem a bit. PyNumberMethods is being
accessed properly, so i mistitled this thread. The problem is that
the MyObject_add() method is called only when both operands being
added are the same type. IOW, MyObject_add() is called only when
adding "MyObject + MyObject" and isnt called when adding "MyObject +
8". How, using an extension type, can you implement "apples +
oranges"???
Clearly it is beneficial to enforce type safety and only allow "apples
+ apples" but there are other times when it is necessary to have the
flexibility to do "apples + oranges". For instance, I may want to be
able to add a stock variable with a flow variable in addition to
adding two stock variables. How can i tweak the addition method for
an extension type to be able to accommodate this?
TIA,
doug_bartholomew99 at yahoo.com
More information about the Python-list
mailing list