because I donβt know the locale settings
You can see this with the locale module :
>>> locale.nl_langinfo(locale.RADIXCHAR) '.'
or
>>> locale.localeconv()['decimal_point'] '.'
Using this, your code could become:
import locale _locale_radix = locale.localeconv()['decimal_point'] def read_float_with_comma(num): if _locale_radix != '.': num = num.replace(_locale_radix, ".") return float(num)
Even better, the same module has a conversion function for you called atof() :
import locale def read_float_with_comma(num): return locale.atof(num)
Martijn pieters
source share