Division oddity

Paul Rubin http
Mon Jan 12 04:49:51 EST 2004


Robin Becker <robin at jessikat.fsnet.co.uk> writes:
> Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from __future__ import division
> >>> eval('1/2')
> 0.5
> >>>
> 
> so  I guess pythonwin is broken in this respect.

Huh?  you get the expected result with both python and pythonwin.  Neither
one is broken.  The surprising result is from input(), not eval():

    $ python
    Python 2.2.2 (#1, Feb 24 2003, 19:13:11) 
    [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from __future__ import division
    >>> print input('expression: ')
    expression: 1/2
    0
    >>> print eval('1/2')
    0.5
    >>> 

That's because input evaluates its string in the context of a
different module which was compiled with old-style division.  I don't
know of other functions that use eval like that, and input() should
be deprecated or eliminated anyway, so this isn't a big deal.



More information about the Python-list mailing list