Python 如何在显示的特定部分获取用户输入

How to have the user input taken in a certain part of the display in Python

我需要知道如何让 Python 项目在显示文本的中间而不是末尾请求用户输入。

示例:

name=input(("Whats your name? [ ]"))

我希望在 [ ] 之间接受用户输入 所以,它会让你在那里输入你的名字。我试着移动 (),所以代码看起来像这样:name=input("Whats your name?" ("[ ]")),但我得到这个错误:

TypeError: 'str' object is not callable

所以,如果您知道为什么会出现此错误,但不知道如何修复它,我将非常感谢有关该错误的信息,如果您知道该答案,我将非常感谢那两个。也许我需要导入一个模块。

来自Blckknght

You could try appending several "\b" backspace characters to the end of your prompt string. On many (but perhaps not all) consoles those will make the input cursor move to the left. Your right bracket won't move with the input though, so you'll need to space it out enough to fit the largest name you expect to get. This is probably the only approach short of using curses or another console GUI library. That worked perfectly, thank you BlackNight!