locale.delocalize(): only call localeconv() once

This commit is contained in:
Victor Stinner 2015-11-03 14:34:51 +01:00
parent bbfcb3895a
commit 2753a096e0
1 changed files with 6 additions and 2 deletions

View File

@ -303,12 +303,16 @@ def str(val):
def delocalize(string):
"Parses a string as a normalized number according to the locale settings."
conv = localeconv()
#First, get rid of the grouping
ts = localeconv()['thousands_sep']
ts = conv['thousands_sep']
if ts:
string = string.replace(ts, '')
#next, replace the decimal point with a dot
dd = localeconv()['decimal_point']
dd = conv['decimal_point']
if dd:
string = string.replace(dd, '.')
return string