1 |
On 1/13/21 7:57 PM, n952162 wrote: |
2 |
> On 1/13/21 7:31 PM, n952162 wrote: |
3 |
>> Hello. In python3, how do you do this? |
4 |
>> |
5 |
>> tgt = 'gebuchte Umsätze;' |
6 |
>> |
7 |
>> In python2, you could do this: |
8 |
>> |
9 |
>> tgt = unicode ('gebuchte Umsätze;'.decode ('latin1')) |
10 |
>> |
11 |
>> but that gives: |
12 |
>> |
13 |
>> SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xe4 in |
14 |
>> position 12: invalid continuation byte |
15 |
>> |
16 |
>> In fact, any constant with ä in it will give you that. |
17 |
>> |
18 |
>> |
19 |
> |
20 |
> Okay, I see that if your locale is not C, you can do: |
21 |
> |
22 |
> tgt = 'gebuchte Umsätze;' |
23 |
> |
24 |
> |
25 |
> |
26 |
|
27 |
Okay, I see I had this bit of magic in line 2: |
28 |
|
29 |
# -*- coding: utf-8 -*- [ this has to be in line1 or line2!!! ] |
30 |
|
31 |
I've removed that and the error msg is somewhat different: |
32 |
|
33 |
SyntaxError: Non-UTF-8 code starting with '\xe4' in file test.py on line |
34 |
89, but no encoding declared; see http://python.org/dev/peps/pep-0263/ |
35 |
for details |
36 |
|
37 |
Note that line 89 is a *comment* (with a ä) |
38 |
|
39 |
So, I'm looking into that... |
40 |
|
41 |
Oh, I think that gave me a solution! |
42 |
|
43 |
# -*- coding: latin1 -*- [ this has to be in line1 or line2!!! ] |
44 |
|
45 |
seems to work. At least, I got some other errors now ;-) |