Python多行输入
有没有办法在Python中进行多行输入?我见过的解决方案不允许您在按下 Enter 后编辑过去的行并遇到其他问题。我正在用Python制作一个简单的文本编辑器,我想要一个可以是多行的文本输入,并且按向左或向右等按钮可以移动文本光标。我需要它在按下某些按钮(例如 ctrl-s 或 ctrl-q)时停止接受输入。因此,如果有一种方法可以按照这些规则获取文本输入,并指定在结束输入时按下哪个按钮来结束输入,那就太好了。例如,一个函数将返回一个包含按下的按钮和文本的元组。
我是从控制台执行此操作的。
Is there any way to have multi-line input in Python? Solutions I have seen don't allow you to edit past lines after you have pressed enter and have other problems. I am making a simple text editor in Python and I want to have a text input that can be multiline and pressing buttons like left or right would move the text cursor. I need it to stop taking input when certain buttons are pressed, like ctrl-s or ctrl-q. So it would be nice if there was a way to get text input following these rules that would specify which button had been pressed to end the input when it was ended. For example, a function that would return a tuple with the button pressed and the text.
I am doing this from the console.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想看一下
curses
模块,它允许您控制控制台输入和输出的各个方面。从官方 HOWTO 开始: http://docs.python.org/howto/curses.html< /a>You might want to take a look at the
curses
module that allows you to control various aspects of console input and output. Start with the official HOWTO: http://docs.python.org/howto/curses.html