http://www.cnblogs.com/linhaifeng/articles/5984922.html
# f=open('test11.py','rb',encoding='utf-8') #报错,b的方式不能指定编码 f=open('test11.py','rb') data=f.read() #'字符串'---------encode---------》bytes #bytes---------decode---------》'字符串' print(data) print(data.decode('utf-8')) f.close() 运行结果: b'hello1 22222 33333 4444 xe4xbdxa0xe5xa5xbdxe5x95x8axe6x9ex97xe5xb8x88xe5x82x85' hello1 22222 33333 4444 你好啊林师傅 f=open('test22.py','wb') #b的方式不能指定编码 f.write(bytes('1111 ',encoding='utf-8')) f.write('杨件'.encode('utf-8')) #以上2种写入方式都可以