Division oddity

Robin Becker robin at jessikat.fsnet.co.uk
Mon Jan 12 10:18:26 CET 2004


In article <7xeku5vrn8.fsf at ruckus.brouhaha.com>, Paul Rubin <http@?.cx>
writes
>Tim Rowe <tim at remove_if_not_spam.digitig.co.uk> writes:
>> If I do from __future__ import division then eval(1/2) gives me 0.5 as
>> expected. But if I do print input("enter a sum: ") and enter 1/2 as
>> the sum I get 0 as if I hadn't done the import.  I thought input was
>> supposed to give the same behaviour as an eval on raw input -- why the
>> difference here?
>
>The input function is calling eval from the context of the module
>where 'input' itself is defined.  If you use "from __future__ import
>division" in module A and have "print 3/2" in module B, the value of
>3/2 in module B shouldn't be affected by the input, since module B
>may depend on integer division having the old behavior.
>
>The result is a little bit surprising at first glance though, so it
>should probably be documented.
I get this in pythonwin with 2.3.2

PythonWin 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)]
on win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>> from __future__ import division
>>> eval('1/2')
0.5
>>> 

In python I get 


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.
-- 
Robin Becker



More information about the Python-list mailing list