translating foreign data

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jun 23 22:44:03 EDT 2018


On Sat, 23 Jun 2018 17:05:17 -0400, Richard Damon wrote:

> On 6/23/18 11:27 AM, Steven D'Aprano wrote:
>> On Sat, 23 Jun 2018 09:42:29 -0400, Richard Damon wrote:
>>
>>> On 6/23/18 9:05 AM, Marko Rauhamaa wrote:
>>>> Ok. Here's a value for you:
>>>>
>>>>     100€

[...]
> Locale based currency transformations are defined as a number to/from a
> text string.
> 
> The number CAN'T say 100 Euros (can you give me what bit pattern you
> would use for such a number).

You're joking, right? You can't possibly be so ignorant as to actually 
believe that. You have, right in front of you, a news post or email 
containing the text string "100€", and yet you are writing apparently in 
full seriousness that it is impossible to get that text string in a file.

Okay, you want a bit-pattern. In hex:

'0x313030e282ac'

I'll leave the question of how I generated that as an exercise. (Hint: it 
was a one-liner, involving two method calls and a function call, all 
builtins in Python.)


> The currency is encoded in the locale used for the conversion, so if it
> is using en-US, the currency value would ALWAYS be US$ (which the
> general locale format is just $).

I cannot imagine for a second why you think any of this is even a tiny 
bit relevant to the question of how one should read a data file 
containing currency in Euro.

You seem to have heard about the locale and decide it is the One True 
Hammer than all nails must be hammered with.


-- 
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