我的字符串跨越多行,导致终端滚动到最新的打印行。但是我想停留在第一行,这样我才能看到第一行而不是最新行。那可能吗?
例如。:
for i in range(100):
print(f"hello {i}")
我想看到
hello 0
但输出应保持相同的形状 最佳答案
如果您使用的是GNU,则可以将defscrollback设置为100。否则,这应该有所帮助:
class More(object):
def __init__(self, num_lines):
self.num_lines = num_lines
def __ror__(self, other):
s = str(other).split("\n")
for i in range(0, len(s), self.num_lines):
print(*s[i: i + self.num_lines], sep="\n")
input("Press <Enter> for more")
more = More(num_lines=30)
"\n".join(map(str, range(100))) | more
关于python - 如何打印输出并保持在同一行(Python)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59986526/