translating foreign data

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jun 23 07:46:23 EDT 2018


On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote:

> If you know the Locale, then you do know what the decimal separator is,
> as that is part of what a locale defines.

A locale defines a set of common cultural conventions. It doesn't mandate 
the actual conventions in use in any specific document.

If I'm in Australia, using the en-AU locale, nevertheless I can generate 
a file using , as a decimal separator. Try and stop me :-)

But your point is taken -- I misread Ethan saying that he knew the locale 
and it wasn't helping, when in fact he was reluctant to change the locale 
as that's a process-wide global change.

> The issue is that if you just
> know the encoding, you don't necessarily know the locale. He also
> commented that he didn't want to set the locale in the routine, as that
> sets it globally for the full application (but perhaps that latter could
> be fixed by first doing a locale.getlocale(), then setlocale for the
> files locale, and then at the end of reading and processing restore back
> the old locale.

Indeed.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list