python 'wb' 模式寫入文件怎么輸出回車


由於'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刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM