由於'wb'模式是二進制輸入,所以要在''前面加上b才能正常寫入.不然會有報錯.
TypeError: a bytes-like object is required, not 'str'
環境 python 3.6
f = open('test.txt', 'wb')
for i in range(3):
f.write(b'hello python\n')
f.close()
由於'wb'模式是二進制輸入,所以要在''前面加上b才能正常寫入.不然會有報錯.
TypeError: a bytes-like object is required, not 'str'
環境 python 3.6
f = open('test.txt', 'wb')
for i in range(3):
f.write(b'hello python\n')
f.close()
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。