How to include newline in python raw_input () function?

I use raw_input() to store a message inside a variable. Therefore, I cannot press enter to return a carriage / new line to start a new paragraph. Right now, if I click on input, it will simply move on to the next part of my program.

I already tried something like this:

 >>> message = raw_input("Message: ") Message: Hello Sir, \n It great that.. >>> message "Hello Sir, \\n It great that.." >>> 

This did not work, and I also tried to include it in single and double quotes, which also did not work.

I understand that there are other ways to do this, for example, using wxpython or tkinter, but I want it to be strictly console. Is it possible?

+6
source share
1 answer

Can you use the sys module? This will do the trick if you want. Just hit Ctrl-D to finish it.

 import sys message = sys.stdin.readlines() 

Otherwise, this will answer your question: Python raw_input ignore newline

+7
source

Source: https://habr.com/ru/post/913663/


All Articles