How to parse floats in a local format without changing the current locale?

Viewed 69

How to parse floats in Python from a source which uses a special known local format that has commas as decimal separators?

locale can do that, of course. But its documentation says:

It is generally a bad idea to call setlocale() in some library routine, since as a side effect it affects the entire program. Saving and restoring it is almost as bad: it is expensive and affects other threads that happen to run before the settings have been restored.

Simply replacing , by . is not such a great solution either.

Can a special locale in Python be used but only for a single parse operation?

0 Answers
Related