0

I need a to make multi-line input in Python. This is part of my program:

input_ = input("Enter text:\n") #This can handle only single line of text

Like this:

Enter text:

This is frst line, #Variable input_ would be only this line
this is second line,
this is last line.

I need something that would ask user to enter text (multi-line text) and when user Paste text (Ctrl + C) and he press Enter, program needs to put whole text into a list.

P.S. Please don't mark this as duplicate, because it's a little diffrent than other questions that doesn't help me.

5
  • How would you know when the input is over? Commented Feb 8, 2015 at 15:44
  • Input is over when user press Enter. Commented Feb 8, 2015 at 15:45
  • In multi line input, you would have a newline character (enter) after each line. How would you distinguish that from the "user entered enter that ends input" ? Commented Feb 8, 2015 at 15:48
  • User needs to paste text, once enter is pressed input is over. Commented Feb 8, 2015 at 15:49
  • See my answer below Ante. The user can paste and then hit enter. Commented Feb 8, 2015 at 15:51

1 Answer 1

0

Try using a while loop:

listed = []
inputs = None

while inputs != '':
    inputs = input()
    listed.append(inputs)

listed = [i for i in listed if i != '']
print listed
Sign up to request clarification or add additional context in comments.

7 Comments

What if I enter "some paragraph\n\nsome paragraph"?
It should work fine until an empty input.
But user needs to press enter twice after an input, can i fix that somehow ?
No, this is as close as you can get to handle the multiline input.
Ok, can you edit your code that saves text into list (1 line = 1 list item)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.