I think we or you are finding your “finish” constraint confusing. You want to end input text. For that text to be finite, Python needs to know when it ends. How do you want to indicate when it ends? Answer from cameron on discuss.python.org
🌐
Reddit
reddit.com › r/learnpython › multi-line input in python 3
r/learnpython on Reddit: Multi-line input in Python 3
June 15, 2019 -

I'm trying to feed a prompt to a GPT-2 model, which is trained on song lyrics. With this model, you can feed it a prompt and it will attempt to finish it. The problem I'm having is that I need for the prompt to be formatted correctly like song lyrics - with each lyric on a newline. Since this model has been trained on formatted lyrics, the prompt needs to look the same to produce above average results.

input() doesn't work, because hitting return submits the text. I've also tried sys.stdin.read() as well and nothing seems to happen, just returns ' '.

Is it because I'm running it in a notebook? I'm only like 8 months deep into this python hobby, so I could be asking for something that can't happen.

Here's the code, would appreciate any ideas you've got.

prompt = input('Input Prompt:')
gpt2.generate(sess,
              length=200,
              temperature=.99,
              prefix= prompt, #this is where the prompt goes
              nsamples=5,
              top_p=.9,
              batch_size=5,
              run_name='run1'
              )
Discussions

python - How to get multiline input from the user - Stack Overflow
I want to write a program that gets multiple line input and work with it line by line. Why isn't there any function like raw_input in Python 3? input does not allow the user to put lines separated by More on stackoverflow.com
🌐 stackoverflow.com
Python: Multiline input converted into a list - Stack Overflow
I have a programming assignment and all of the inputs that I need to enter are multilined. For example: ... I am trying to convert the lines into lists. More on stackoverflow.com
🌐 stackoverflow.com
September 20, 2013
multiline input in terminal - Ideas - Discussions on Python.org
Proposal: put simply, i need to regularly input multiple lines into my terminal and have python interpret that as is. for an oversimplified example: Enter your groceries: kiwi apple banana orange yes, i know there are workarounds such as while loops or sys.stdin.readlines() but those have cons ... More on discuss.python.org
🌐 discuss.python.org
0
November 29, 2024
Store multi-line input into a String (Python) - Stack Overflow
0 Python raw_input, input and other multi-line methods fail to read std input · 2 How to get user input for multiline lines in Python 3? More on stackoverflow.com
🌐 stackoverflow.com
May 14, 2015
Top answer
1 of 3
2

Keep calling the input() function until the line it reads in is empty. The use the .split method (no args = space as deliminator). Use a list-comp to convert each string to an int and append this to your examList.

Here's the code:

examList = []
i = input()
while i != '':
    examList.append([int(s) for s in i.split()])
    i = input()

And with your input, examList is:

[[3], [2, 1], [1, 1, 0], [2, 1, 1], [4, 3, 0, 1, 2], [2], [1, 2], [1, 3]]

The above method is for Python3 which allows you to call input() and enter nothing (which is why we use this as a signal to check that we are done - i != '').

However, from the docs, we see that, in Python2, an empty entry to input() throws an EOF error. To get around this, I guess we could just make it so that the multi-line input is ended when the string such as: END is entered. This means that you must stop the entry with a line saying 'END':

examList = []
i = raw_input()
while i != 'END':
    examList.append([int(s) for s in i.split()])
    i = raw_input()

Note that I've used raw_input as to not perform type conversion.

which works the same as above.

2 of 3
2

You can use sys.stdin.readlines().

For example, start with

import sys
user_input = sys.stdin.readlines()

at this point, the value of user_input should be

['3\n', '2 1\n', '1 1 0\n', '2 1 1\n', '4 3 0 1 2\n', '2\n', '1 2\n', '1 3']

then, you should be able to get your desired output by performing the following processing

examList = []

for input_string in user_input:
   examList.append([int(value) for value in input_string.split()])

What we are doing here is iterating through user_input. For each input_string, we split() the words, convert them to int and put them back into a new list. Then, the new list will be added into examList.

🌐
Bobby Hadz
bobbyhadz.com › blog › python-input-multiple-lines
Multiple lines user Input in Python | bobbyhadz
The readlines() method will return a list containing the lines. The user can press CTRL + D (Unix) or CTRL + Z (Windows) to exit. ... Copied!import sys # 👇️ User must press Ctrl + D (Unix) or Ctrl + Z (Windows) to exit print('Press CTRL ...
🌐
GeeksforGeeks
geeksforgeeks.org › taking-multiple-inputs-from-user-in-python
Taking multiple inputs from user in Python - GeeksforGeeks
December 3, 2024 - One of the simplest ways to take multiple inputs from a user in Python is by using the input() function along with the split() method. The split() method splits a string into a list based on a specified separator (by default, it uses whitespace).
🌐
Sololearn
sololearn.com › en › Discuss › 2881136 › how-to-get-multiline-input-from-user
How to get multi-line input from user? | Sololearn: Learn to code for FREE!
September 13, 2021 - The best way is to create a list and append each input to that list by the append method : listname.append(input) And for the Unlimited inputs you need While True and for the limited input you need( for i in range(argument) ) ... # Python program ...
Find elsewhere
🌐
Profound Academy
profound.academy › python-introduction › multi-line-lists-BLTEtz0sDYdm0zAjIB7S
multi-line lists - Introduction to Python
November 2, 2024 - Once again, each list element can be treated as an ordinary variable like presented on the right. This creates a list with 2 elements which are read from the input.
🌐
W3Schools
w3schools.com › python › gloss_python_multi_line_strings.asp
Python Multiline Strings
Remove List Duplicates Reverse ... Training · ❮ Python Glossary · You can assign a multiline string to a variable by using three quotes: You can use three double quotes: a = """Lorem ipsum dolor sit amet, consectetur adipiscing ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-multi-line-statements
Multi-Line Statements in Python - GeeksforGeeks
June 30, 2025 - Implicit line continuation allows long statements to be split across multiple lines as long as the code is enclosed within parentheses ( ), brackets [ ], or braces { }. ... Explanation: uses (), [] and () to split a string, a list and a math ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-multi-line-statements
Python - Multi-Line Statements - GeeksforGeeks
May 10, 2023 - In this example, we are initializing the list and the mathematical expression using the parentheses ( ), brackets [ ], and braces { } sign which is the implicit line continuation to continue the same line in the multiple lines in python programming.
🌐
Python.org
discuss.python.org › ideas
multiline input in terminal - Ideas - Discussions on Python.org
November 29, 2024 - Proposal: put simply, i need to regularly input multiple lines into my terminal and have python interpret that as is. for an oversimplified example: Enter your groceries: kiwi apple banana orange yes, i know there are workarounds such as while loops or sys.stdin.readlines() but those have cons and dont exactly work as intended. for example, sys.stdin.readlines() would require me to only have one needed multiline input. in my opinion, input() should be for single lines while (something alon...
🌐
StudySmarter
studysmarter.co.uk › python multi input
Python Multi Input: Techniques & Examples | StudySmarter
To develop versatile and dynamic Python applications, understanding how to handle multi input is essential. Python provides several methods to efficiently collect multiple inputs. The examples below demonstrate how to gather multiple lines of input and store them in a list, enhancing your application's interactivity and functionality.
🌐
CSEstack
csestack.org › home › how to read multiline user input in python 2 and 3?
How to Read Multiline User Input in Python 2 and 3?
April 15, 2019 - ... Enter your string in multiple lines. Once you complete giving the user input in multiple lines, press ctrl+d. It sends a signalEOF to your system. If you are a windows user, use ctrl+z instead of ctrl+d. And enter.
🌐
Learn By Example
learnbyexample.org › taking-multiline-input-from-a-user-in-python
Taking multiline input from a user in Python - Learn By Example
April 10, 2024 - For a more Pythonic solution, consider using a list comprehension with iter() function: print("Enter your lines. Type 'END' to finish.") lines = [line.rstrip() for line in iter(input, 'END')] # Assuming 'END' as the terminator print("You entered:") for line in lines: print(line) ... Enter your lines. Type 'END' to finish. Hi Hello How are you? END Your multiline input: Hi Hello How are you?
🌐
Quora
quora.com › How-can-I-take-multiline-input-from-a-user-and-assign-it-to-a-single-variable-in-Python
How to take multiline input from a user and assign it to a single variable in Python - Quora
Answer (1 of 4): First you need to figure out how the user indicates the end of the input. If it’s indicated in the last line (e.g. a blank last line indicates the end of input) you can read things in line-by-line: [code]user_writing = [] while True: line = input() if !line: # If line is blank...
🌐
Delft Stack
delftstack.com › home › howto › python › python input multiple lines
How to Get Multiple-Line Input in Python | Delft Stack
February 20, 2025 - ... The sys module can be imported to the Python code and is mainly utilized for maintaining and manipulating the Python runtime environment. The sys.stdin.read() function is one such function that is a part of the sys module and can be utilized ...