1. 程式人生 > >python3中文件操作及編碼

python3中文件操作及編碼

中文 txt test his 操作 例子 處理 nth window

#之前一直沒明白文件處理中的w和wb的區別到底是什麽,
#在看過視頻後才知道,原來在linux裏面是沒有區別的,
#但是在windows裏面就能夠看出區別來了
#下面來個例子:

with open("普通文本文件.txt", "w",encoding=‘utf-8‘) as f:
data = ‘This is testing!\nThis is testing!‘
f.write(data)
f.close()

with open("二進制文本文件.txt", "wb") as f:
data = b‘This is testing!\nThis is testing!‘


f.write(data)
f.close()

python3中文件操作及編碼