Future division patch available (PEP 238)

Anders J. Munch andersjm at dancontrol.dk
Wed Aug 15 09:22:40 EDT 2001


"Ian Parker" <parker at gol.com> wrote in message
news:YTzPNDAvATe7EwXf at gol.com...
> "19 .py files scanned, 4 affected with 9 instances of the division
> operator."
>
> Now that is much more reasonable, but it is still almost 25% of the
> modules, and I still, if I understand correctly, need to decide which
> ones should be integer division.
>
> For a large project, that might amount to a significant amount of work:
> checking, fixing, testing, regression testing, UAT, change control and
> releasing.
>

Here's an idea on how to avoid that: Replace each instance of / and /=
with a call to a function that emulates old division behaviour. This
could be completely automated.

That is replace each instance of
    E1 / E2
where E1 and E2 are arbitrary expressions, with
    oldstyle_division(E1,E2)

def oldstyle_division(E1,E2):
    if type(E1) == types.IntType and type(E2) == types.IntType:
        return E1 // E2
    else:
        return E1 / E2

- Anders





More information about the Python-list mailing list