float( ) inconsistency?

Tim Peters tim.one at home.com
Sun Nov 18 01:44:48 CET 2001


[José Rui Faustino]
> I am a little bothered by float( ) behaviour.
>
> I think float( '1.0e' ) or float( 1.0e-' ) should not raise an error.
> After all x = 1.0e or x = 1.0e- both are legal floats.

They're not in Python 2.2.  From the NEWS file for 2.2a4:

- The syntax of floating-point and imaginary literals has been
  liberalized, to allow leading zeroes.  Examples of literals now
  legal that were SyntaxErrors before:

      00.0    0e3   0100j   07.5   00000000000000000008.

- An old tokenizer bug allowed floating point literals with an incomplete
  exponent, such as 1e and 3.1e-.  Such literals now raise SyntaxError.

The incomplete literals were never legit according to the Python reference
manual, or to tokenize.py.





More information about the Python-list mailing list