如何在python 3中更改光标的位置

时间:2018-06-03 14:49:16

标签: python python-3.x

我在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()

输出:

enter image description here

想要输出:

enter image description here

ANSI转义序列似乎没有colorama(不幸的是它是一个外部模块)。

2 个答案:

答案 0 :(得分:2)

在Windows 10上,您可以使用Console Virtual Terminal Sequences中的ANSI转义序列。

在使用它们之前,您需要subprocess.run('', shell=True)(在Python 3.5之前,使用subprocess.call)。这些序列使您可以找到所需的信息。

警告:同样是原始Microsoft,在显示中删除在线删除的文档部分错误。参数 1 2 相反。

这应该可行(尽管实际输入密码似乎会破坏布局):

import subprocess
subprocess.run('', shell=True)
print(' enter password : \0337', end='')
print('\n\n\t2 attempts remaining .\0338', end='')
x = input()

答案 1 :(得分:-1)

使用Python 3;

print("...", end="")