简体   繁体   中英

Python multi-line input

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.

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

import sys
print("Message? (Ctrl+D to end)")
msg = sys.stdin.readlines()
print(msg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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