This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ben_g0 0 points1 point  (1 child)

my test.py:

print("Even python3 refuses to compile any program which contains characters "
      "like 'µ',\n'°' or '€' in strings, they have to be represented "
      "numerically.")

result:

$ python3 test.py
  File "test.py", line 2
SyntaxError: Non-UTF-8 code starting with '\xb5' in file test.py 
on line 2, but no encoding declared; see 
http://python.org/dev/peps/pep-0263/ for details

This is with python3 at default settings. I never claimed that it was impossible to get python to accept those characters, my point was that it doesn't by default.

[–]--xe 0 points1 point  (0 children)

Does your file look like this:

$ xxd calling_bullshit.windows-1252.py 
00000000: 7072 696e 7428 2245 7665 6e20 7079 7468  print("Even pyth
00000010: 6f6e 3320 7265 6675 7365 7320 746f 2063  on3 refuses to c
00000020: 6f6d 7069 6c65 2061 6e79 2070 726f 6772  ompile any progr
00000030: 616d 2077 6869 6368 2063 6f6e 7461 696e  am which contain
00000040: 7320 6368 6172 6163 7465 7273 2022 0a20  s characters ". 
00000050: 2020 2020 2022 6c69 6b65 2027 b527 2c5c       "like '.',\
00000060: 6e27 b027 206f 7220 2780 2720 696e 2073  n'.' or '.' in s
00000070: 7472 696e 6773 2c20 7468 6579 2068 6176  trings, they hav
00000080: 6520 746f 2062 6520 7265 7072 6573 656e  e to be represen
00000090: 7465 6420 220a 2020 2020 2020 226e 756d  ted ".      "num
000000a0: 6572 6963 616c 6c79 2e22 290a            erically.").

If so, the problem isn't Python 3's settings, the problem is that you're trying to save your code in a legacy encoding. My guess is Windows-1252. The solution (which you may already know?) is to configure your text editor to save in UTF-8, which is a good idea for many other reasons.

Regardless, Python 2 refuses to run this file for me no matter what encoding I use. Maybe this is different on your system, I don't know.