删除 Python 打印行中的字符 [英] Delete Characters in Python Printed Line
本文介绍了删除 Python 打印行中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个程序,我希望光标在同一行上打印字母,但随后也将它们删除,就好像有人在打字,犯了一个错误,删除回错误,然后继续打字
I'm writing a program where I want the cursor to print letters on the same line, but then delete them as well, as if a person was typing, made a mistake, deleted back to the mistake, and kept typing from there.
到目前为止,我所拥有的只是将它们写在同一行上的能力:
All I have so far is the ability to write them on the same line:
import sys, time
write = sys.stdout.write
for c in text:
write(c)
time.sleep(.5)
推荐答案
write('\b') # <-- backup 1-character
这篇关于删除 Python 打印行中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文