Python carriage return not working

巧了我就是萌 提交于 2019-12-02 02:14:45

Using \r is probably the correct way to go here, but the behaviour depends very much on how the text is being output. Not all terminals will respect a bare carriage return:

cmd.exe and powershell.exe should both output the text the way you expect (Powershell ISE doesn't but that's a red herring here).

Python's own idle will ignore the carriage return, all output comes on one long line.

As you noted, your own editor's command window also ignores \r.

Also, if you try from an interactive window you also get some numbers output at the end of each line: that's because the interactive windows helpfully outputs the result of the call to sys.stdout.flush().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!