0A hex bug on writing to file?

前端 未结 1 1670
谎友^
谎友^ 2021-01-16 09:46

I have a little problem: why does this code

somefile = open(\'foo.txt\', \'w\')
somefile.write(\'0B0B0B\'.decode(\'hex\'))
somefile.close()

相关标签:
1条回答
  • 2021-01-16 10:12

    It comes from the \n -> \r\n transformation due to the fact that you're running on Windows. Open the file in binary mode ('wb') if you want to avoid this.

    0 讨论(0)
提交回复
热议问题