PEP238 and zope

Barry A. Warsaw barry at zope.com
Wed Jul 25 10:48:19 EDT 2001


>>>>> "CT" == Christian Tanzer <tanzer at swing.co.at> writes:

    CT> This isn't portable behavior. According to the python library
    CT> reference, `int` may round on some platforms.

It also says:

    "This is ugly -- the language definition should require truncation
    towards zero."

Okay so

    int(math.floor(a / b))

or

    divmod(a, b)[0]

are better.  Either way, wrap it in a function called "div()" and use
that where ever you absolutely must have integer division.

really-portable-code-is-always-ugly-anyway-ly y'rs,
-Barry




More information about the Python-list mailing list