在使用input()
函数时,我希望从用户获取或接收一个字符串到一个变量。那么,可以在方括号内输入而不是纯文本吗?例如
a = input("-->")
这显示了这样的输出:
-->
但是我可以得到这样的输出吗:
--> [ _ ]
并在方括号内输入。(_
表示光标。(
调用input()
时操作光标位置需要使用ANSI转义序列进行破解。(请参阅@chepner的答案。(为了更正确地完成您想要的操作,您需要使用一个可以操作终端的库,例如curses。
你可以。如果您的终端支持ANSI转义序列,则可以通过输出