Very basic question

Sion Arrowsmith siona at
Tue Dec 23 12:23:16 CET 2008

Sengly  <Sengly.Heng at> wrote:
>I would like to calculate a string expression to a float. For example,
>I have ('12/5') and I want 2.4 as a result. I tried to use eval but it
>only gives me 2 instead of 2.5

py> from __future__ import division
py> print eval('12/5')
py> print eval('12//5')

Or switch to 3.0 which gives you this behaviour without the __future__

\S -- siona at --
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list