[Tutor] Problem with division in Python22

Gregor Lingl glingl@aon.at
Tue, 22 Jan 2002 08:13:14 +0100


Thanks, this works!

But hasn't this to be considered as a bug,
as it breaks code developed for up to 2.2?
Gregor

----- Original Message ----- 
From: "Kirby Urner" <urnerk@qwest.net>
To: "Gregor Lingl" <glingl@aon.at>
Cc: <tutor@python.org>
Sent: Tuesday, January 22, 2002 4:53 AM
Subject: Re: [Tutor] Problem with division in Python22


> 
> I don't have the qnew program handy, but how about
> if you change
> 
> __div__
> 
> to
> 
> __truediv__
> 
> in your class def?  That's supposed to be the interim
> thing to override when you've got futuristic division
> activated -- until it becomes the default.
> 
> See (scroll down to API Changes):
> http://python.sourceforge.net/peps/pep-0238.html
> 
> Kirby
> 
> PS:  another fun operator to override in the fraction
> class is __pow__, to allow F(2,3)**2 -> (4/9).  But
> don't forget to implement negative powers, e.g.
> F(2,3)**(-1) -> (3/2).  If this is implemented, then
> instead of x/y, you can alternatively write x * y**(-1).
> 
> 
> 
>