1 |
On 1/13/21 7:59 PM, Grant Edwards wrote: |
2 |
> On 2021-01-13, n952162 <n952162@×××.de> wrote: |
3 |
> |
4 |
>> Hello. In python3, how do you do this? |
5 |
> Please explain what "this" is trying to accomplish, and we can tell |
6 |
> you how to do it in Python3. Are you trying to convert from Unicode to |
7 |
> Latin1 and back to Unicode? |
8 |
> |
9 |
> Python 3.8.6 (default, Jan 2 2021, 20:25:58) |
10 |
> [GCC 9.3.0] on linux |
11 |
> Type "help", "copyright", "credits" or "license" for more information. |
12 |
> >>> 'gebuchte Umsätze;'.encode('latin1').decode('latin1') |
13 |
> 'gebuchte Umsätze;' |
14 |
> |
15 |
> |
16 |
I'm trying to search for a string in a file. I don't know why there |
17 |
needs to be any conversion going on. |
18 |
|
19 |
Just running python3 in interactive mode, I can input the literal when |
20 |
the locale is right: |
21 |
|
22 |
12/lcl/data/f/b>LC_ALL=de_DE python3 |
23 |
Python 3.7.9 (default, Nov 16 2020, 00:32:07) |
24 |
[GCC 9.3.0] on linux |
25 |
Type "help", "copyright", "credits" or "license" for more information. |
26 |
Could not open PYTHONSTARTUP |
27 |
FileNotFoundError: [Errno 2] No such file or directory: |
28 |
'/home/mellman/lib/python/rpnrc' |
29 |
>>> s = "gebuchte Umsätze" |
30 |
>>> print (s) |
31 |
gebuchte Umsätze |
32 |
>>> |
33 |
|
34 |
but it doesn't work from within my pgm... |
35 |
|
36 |
With python2, I presume there was conversion going on because ... a |
37 |
string can't have unicode chars, so it must be a unicode string that has |
38 |
to be decoded. |
39 |
|
40 |
tgt = unicode ('gebuchte Umsätze;'.decode ('latin1')) |
41 |
|
42 |
But python3 is supposed to make all that superfluous ... I thought that |
43 |
was a major driving factor for python3 ... that everything was unicode, |
44 |
conversion wouldn't be necessary. |