Version compatibility in division

Lulu of the Lotus-Eaters mertz at gnosis.cx
Mon Jul 23 15:03:33 EDT 2001


IMO, there has been a lot more heat than light generated--on both
sides--in the discussion of changes in integer division operators.

I don't want to opine on either side, actually.  The issue of checking
old code for breakage is something I believe can be reasonably
automated, and not require horribly much work.  That is, it will not
be horrible *if* a script is simply updated for a new Python version.

But in reading the threads, the most significant argument against the
change, to my mind, has been the problem with maintaining scripts that
must run across multiple Python versions.  I'd like to hear how PEP238
proponents suggest best updating a script like the below.  I don't mean
this as a rhetoric suggestion that it cannot be done, but as a genuine
question of the best idiom:

    #!/usr/bin/python
    # Simple script using integer division.
    # Script MUST run under various Python versions without change
    widget = input('widget size: ')
    container = input('container size: ')
    print container/widget,'widgets will fit in the container'

Obviously, anything with 'from __future__ ...' fails in some versions.
And anything with '//' fails in some versions.  One could catch such
exceptions, but that gets verbose quickly.

Yours, Lulu...




More information about the Python-list mailing list