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