Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Python Encoding error with some unicode characers

I am having some problems with encoding some unicode characters. This is the code I am using:

test = raw_input("Test: ")
print test.encode("utf-8")

When I use now normal ASCII characters it works, same with some "strange" unicode characters like ☃. But when I use characters like ß ä ö ü § it fails creating this error:

Traceback (most recent call last):
 File "C:\###\Test.py", line 5, in <module>
 print test.encode("utf-8")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xdf in position 0: ordinal not in range(128)

Note that I am using a pc where German is the default language (so these characters are default characters).

Answer*

Draft saved
Draft discarded
Cancel

lang-py

AltStyle によって変換されたページ (->オリジナル) /