mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Replace sequential split/join calls on strings with a single replace call.
Thanks Andrew Gaul.
This commit is contained in:
parent
708b4dacf4
commit
aaeffaf01e
2 changed files with 5 additions and 11 deletions
|
@ -159,18 +159,16 @@ def str(val):
|
|||
"""Convert float to integer, taking the locale into account."""
|
||||
return format("%.12g",val)
|
||||
|
||||
def atof(str,func=float):
|
||||
def atof(string,func=float):
|
||||
"Parses a string as a float according to the locale settings."
|
||||
#First, get rid of the grouping
|
||||
ts = localeconv()['thousands_sep']
|
||||
if ts:
|
||||
s=str.split(ts)
|
||||
str="".join(s)
|
||||
str = str.replace(ts, '')
|
||||
#next, replace the decimal point with a dot
|
||||
dd = localeconv()['decimal_point']
|
||||
if dd:
|
||||
s=str.split(dd)
|
||||
str='.'.join(s)
|
||||
str = str.replace(dd, '.')
|
||||
#finally, parse the string
|
||||
return func(str)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue