1

エンコーディングの仕組みを理解するのに苦労しています:

Python コード内の文字列をエンコードできる理由:

s = 'Au\xc3\x9fenformat\n'
print s.encode('utf-8')
>>>Außenformnat

しかし、テキスト ファイルからそのような文字列を読み取ると、次のようになります。

f = open('out.txt', 'r')
data = f.read()
print data.encode('utf-8')
>>>Au\xc3\x9fenformat\n

助言がありますか?

4

2 に答える 2

0
>>> f = open('out.txt', 'r')
>>> data= f.read()
>>> print data.decode("string_escape")
ußenformat
于 2013-04-22T16:45:09.653 に答える