繁体   English   中英

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

[英]how to change the position of the cursor in python 3

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

输出:

在此输入图像描述

想要输出:

在此输入图像描述

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

在Windows 10上,您可以使用控制台虚拟终端序列中的 ANSI转义序列。

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

警告:同样是原版Microsoft, 显示擦除行中擦除文档部分有问题。 参数12相反。

这应该工作(虽然,实际输入密码似乎破坏了布局):

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

用Python 3使用;

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM