I'm using Python 3.6 and trying to read a multi-line input to store it in a variable and then manage each line in a list for example. The structure of the code is something simple like this:
print("Escriba la lista de ciudades de la siguiente forma:")
print("Ciudad origen | Ciudad destino | Ruta | Distancia")
cad.append(input())
I want to enter 3 lines for example (without pressing ENTER, copying and pasting for example)
Line 1
Line 2
Line 3
And I want python to store the 3 lines in a variable
Input
(python 3.x) returns a string, to split each element you can usesplit
the strings method using the appropriate separator, in your case|
:Edit: Ok, what you want by the looks of it is multiline input, input only reads until it hits an end of line ('\n', '\r', ...).
while
A simple way would be to use an infinite loop . To stop the entry you can specify anything, in this case entering a blank line indicates that the user ends the data entry:In this case you can copy and paste a text with several lines in the console and finally each line will be an element of the list.