0

I want to be able to accept multi-line user input. The problem is that with my program the user can't just use Shift Enter to do it.

I want them to be able to paste in several paragraphs for translation and when it detects a new line it automatically takes it as an enter and cuts off the input. I am using raw_input, not input.

Does anyone know a way to overcome this, so it can accept pasted text with multiple lines without assuming it is the end of the input?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
Adam Griffiths
  • 821
  • 3
  • 23
  • 53

1 Answers1

1

You can repeatedly ask for raw_input() in a loop and concatenate the lines until you hit some input that signalizes the end. A very common one would be an empty line:

allLines = []
print('Insert the text:')
while True:
    line = raw_input('')
    if line == '':
        break
    allLines.append(line)

fullInput = '\n'.join(allLines)
print('You entered this:')
print(fullInput)
poke
  • 339,995
  • 66
  • 523
  • 574