[Python-bugs-list] [ python-Bugs-620181 ] float('+ 0.0') fails

noreply@sourceforge.net noreply@sourceforge.net
Wed, 09 Oct 2002 09:30:37 -0700


Bugs item #620181, was opened at 2002-10-08 07:14
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=620181&group_id=5470

Category: Python Interpreter Core
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 2
Submitted By: Alexander Schmolck (aschmolck)
Assigned to: Nobody/Anonymous (nobody)
Summary: float('+ 0.0') fails

Initial Comment:
In [25]: int('+ 0')
Out[25]: 0

In [26]: float('+ 0.0')

ValueError: invalid literal for float(): + 0.0



----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-10-09 11:30

Message:
Logged In: YES 
user_id=80475

Looking at the source for PyOS_strtol, it appears to be a 
implement quirk that int() accepts whitespace between 
the sign and the rest of the number.  Since it's possible 
that people rely on the quirk (some accounting formats do 
print intermediate whitespace after the sign), this quirk 
probably should be left alone.

float() uses platform's strtod() function which tries various 
strategies for making sense of the string.  Liberalizing float
() to match int()'s unintended quirk would involve trying to 
work around the strtod() black box and cluttering the code 
considerably.

I recommend living with the minor inconsistency, closing 
the bug report, and moving on to bigger game.

----------------------------------------------------------------------

Comment By: Alexander Schmolck (aschmolck)
Date: 2002-10-08 12:41

Message:
Logged In: YES 
user_id=559641

I don't feel strongly about this, it just seems a very minor
inconsistency to me. It is not always true that embedded
whitespace isn't accepted in numeric literals. Whitespace
between sign and digits is discarded by `int`, but not by
`float`. Also, in source code or in interactive sessions -
0.0 is treated as a float literal (not as unary negation of
0.0), wheras "2 3" just never works.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-10-08 11:02

Message:
Logged In: YES 
user_id=31435

Why do you think this is a bug?  It's *generally* true that 
embedded whitespace isn't accepeted in numeric literals:

>>> int("2 3")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 2 3
>>> import string
>>> string.atof("- 2")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Code\python\lib\string.py", line 201, in atof
    return _float(s)
ValueError: invalid literal for float(): - 2
>>>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=620181&group_id=5470