Make Python stop emitting a carriage return when writing newlines to sys.stdout

前端 未结 2 1359
清歌不尽
清歌不尽 2020-12-18 23:24

I\'m on Windows and Python is (very effectively) preventing me from sending a stand-alone \'\\n\' character to STDOUT. For example, the following will output

2条回答
  •  萌比男神i
    2020-12-19 00:12

    Add 'r' before the string:

    sys.stdout.write(r"foo\nvar")
    

    As expected, it also works for print.

提交回复
热议问题