这是我的代码:
import sys, os
print("█████") #<-- Those are solid blocks.
f= open('file.txt')
for line in f:
print(line)
在 file.txt 中是这样的:
hay hay, guys
████████████
但输出是这样的:
██████
hay hay, guys <----- ***Looks like it outptutted this correctly!***
Traceback (most recent call last):
File "echofile.py", line 6, in <module>
print(line)
File "C:\python33\lib\encodings\cp437.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 1-2: cha
racter maps to <undefined> <------ ***But not from the file!***
有人对它为什么这样做有任何建议吗?我在 IDLE 中编写了代码,尝试在 Programmer's Notepad 和 IDLE 中编辑 file.txt。该文件是 ASCII / ANSI。顺便说一句,我正在使用 Python 3。3.3 alpha win-64 如果重要的话。