__div__ not recognized automatically

Tuomas tuomas.vesterinen at pp.inet.fi
Thu Nov 2 21:23:28 CET 2006


Try
a=(b+c)/NumX(2)

TV

Anton81 wrote:
> 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