PyCharm print end='\r' 语句不起作用 [英] PyCharm print end='\r' statement not working
问题描述
已经有很多关于打印语句的其他问题,但我还没有找到我的问题的答案:
There are already lots of other questions about the print statement, but I have not found an answer to my problem:
当我这样做时:
for idx in range(10):
print(idx, end="\r")
直接在(ipython)终端中,它工作正常并且总是覆盖上一行.但是,当在带有 PyCharm 的模块中运行它时,我没有在标准输出中看到任何行.
in the (ipython) terminal directly, it works fine and always overwrites the previous line. However, when running this in a module with PyCharm, I don't see any lines printed in the stdout.
这是已知的 PyCharm 问题吗?
Is this a known PyCharm issue?
推荐答案
尝试在打印字符串的开头(而不是结尾)添加 \r
:
Try to add \r
at the beginning of your printed string (not at the end):
for idx in range(10):
print('\r', idx, end='')
回车在前面,并以 '' 结尾以避免换行 '\n'.避免空格的一种解决方案是使用格式约定:
Carriage return at front, and end with '' to avoid new line '\n'. One solution to avoid the space is to use the format convention:
for idx in range(10):
print("'\r{0}".format(idx), end='')
这篇关于PyCharm print end='\r' 语句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!