Python Write bytes to file

前端 未结 2 818
醉话见心
醉话见心 2020-12-23 19:48

I have a function that returns a string. The string contains carriage returns and new line feeds (0x0D, 0x0A). However when I write to a file it contains only the new line f

相关标签:
2条回答
  • 2020-12-23 20:28

    Write bytes and Create the file if not exists:

    f = open('./put/your/path/here.png', 'wb')
    f.write(data)
    f.close()
    
    0 讨论(0)
  • 2020-12-23 20:44

    If you want to write bytes then you should open the file in binary mode.

    f = open('/tmp/output', 'wb')
    
    0 讨论(0)
提交回复
热议问题