__div__ not recognized automatically

Anton81 usenet1 at anton.e4ward.com
Thu Nov 2 06:59:32 EST 2006


Hello!

I wrote a class

class NumX:
  ...
  def __add__(self,other):
    ...
  def __div__(self,other):
    if not isinstance(other,NumX): other=NumX(other)
    ...

Somewhere else I use

a=(b+c)/2

where all variables are of NumX Type. When I execute the program it
complains that it can't find an operator "/" for "instance" and "integer".
However if I use pdb the same command works when started on the prompt. Also
the manual execution

a=(b+c).__div__(2)

works. Any suggestions what goes wrong?

Anton



More information about the Python-list mailing list