我在 Windows 10 上,我不想安装新模块(接受标准库解决方案)。我希望用户输入的文本从第三行的末尾开始。
我的代码:
print(" Enter password to unlock the Safe .\n\n password : \n\n\t2 attempts remaining .")
# code to move the cursor to the end of " password : " goes here
x = input()
输出:
想要的输出:
如果没有 colorama(不幸的是它是一个外部模块),ANSI 转义序列似乎也无法工作。
最佳答案
在 Windows 10 上,您可以使用 Console Virtual Terminal Sequences 中的 ANSI 转义序列。 .
在使用它们之前,您需要 subprocess.run('', shell=True)
(在 Python 3.5 之前,使用 subprocess.call
)。这些序列使您正在寻找的东西成为可能。
警告:同样是 Microsoft 原创,Erase in Display 和 Erase in Line 的文档有部分错误。参数1和2被颠倒了。
这应该可行(尽管实际上输入密码似乎破坏了布局):
import subprocess
subprocess.run('', shell=True)
print(' enter password : \0337', end='')
print('\n\n\t2 attempts remaining .\0338', end='')
x = input()
关于python - 如何在python 3中更改光标的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50667636/