level 1
PMHI💯
楼主
今天刚学python3 听说是unicode编码 就试着输出了一下十二星座 如下:
>>> for i in range(0,12):
print(chr(9800+i),end="->")
♈->♉->♊->♋->♌->♍->♎->♏->♐->♑->♒->♓->
完全OK 莫得问题
然后我就想输出到文件里面看下是什么样的,结果报了一个编码错误,代码和报错如下,请问大家这是为什么啊?
>>> f = open('D:/printtext.txt','w+')
>>> for i in range(0,12):
print(chr(9800+i),end="->",file=f,flush=True)
Traceback (most recent call last):
File "<pyshell#47>", line 2, in <module>
print(chr(9800+i),end="->",file=f,flush=True)
UnicodeEncodeError: 'gbk' codec can't encode character '\u2648' in position 0: illegal multibyte sequence
2020年03月08日 18点03分
1
>>> for i in range(0,12):
print(chr(9800+i),end="->")
♈->♉->♊->♋->♌->♍->♎->♏->♐->♑->♒->♓->
完全OK 莫得问题
然后我就想输出到文件里面看下是什么样的,结果报了一个编码错误,代码和报错如下,请问大家这是为什么啊?
>>> f = open('D:/printtext.txt','w+')
>>> for i in range(0,12):
print(chr(9800+i),end="->",file=f,flush=True)
Traceback (most recent call last):
File "<pyshell#47>", line 2, in <module>
print(chr(9800+i),end="->",file=f,flush=True)
UnicodeEncodeError: 'gbk' codec can't encode character '\u2648' in position 0: illegal multibyte sequence