# 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\r\n22222\r\n33333\r\n4444\r\n\xe4\xbd\xa0\xe5\xa5\xbd\xe5\x95\x8a\xe6\x9e\x97\xe5\xb8\x88\xe5\x82\x85'hello122222333334444你好啊林师傅f=open('test22.py','wb') #b的方式不能指定编码f.write(bytes('1111\n',encoding='utf-8'))f.write('杨件'.encode('utf-8'))#以上2种写入方式都可以