Version compatibility in division
Duncan Grisby
dgrisby at uk.research.att.com
Wed Jul 25 05:32:42 EDT 2001
In article <loj77.544242$eK2.114179510 at news4.rdc1.on.home.com>,
Nick Perkins <nperkins7 at home.com> wrote:
>I suppose the only cross-version solution would be:
>
> # Script MUST run under various Python versions without change
> ...
> print int(container/widget) ,'widgets will fit in the container'
>
>It's a tiny bit verbose, but at least it's very explicit.
And also wrong in the face of negative divisors (although you probably
wouldn't have a negative number of widgets :-) ).
>>> 5/-2
-3
>>> int(5.0/-2.0)
-2
The "simple" solution is divmod(container, widget)[0]. Lovely.
Cheers,
Duncan.
--
-- Duncan Grisby \ Research Engineer --
-- AT&T Laboratories Cambridge --
-- http://www.uk.research.att.com/~dpg1 --
More information about the Python-list
mailing list