When I try to use multiple multilines input, the second multiline input interpret the ctrl + d as his and does not wait for my new input. Even if I try to use another simple input it does not work. I tried with the loop and with the sys readlines() but it does not work. I think the issue is with the EOFError used to finish the first multiline.
Here is my code:
import sys
print("Please paste a multiline code and press ctrl + d")
userInput1 = sys.stdin.readlines()
print(userInput1)
print("Please paste a multiline code and press ctrl + d")
userInput2 = sys.stdin.readlines()
print(userInput2)
userInput3 = input("Input something")
print(userInput3)
I even did with a loop but the result is the same:
def getl():
try:
x = input()
except EOFError:
return ""
return x
def getline():
text = []
line = self.getl()
while line != "":
text.append(line)
line = self.getl()
print(text)
print("Please paste a multiline code and press ctrl + d")
input1 = getline()
print(input1)
print("Please paste a multiline code and press ctrl + d")
input2 = getline()
print(input2)
I even tried with another while loop! LOL
def input_lines_to_list(text, list):
list = list
print(text)
have_lines = True
while have_lines:
try:
line = input()
except EOFError:
break
list.append(line)
if line == "":
have_lines = False
return list
text = "Please paste a multiline code and press ctrl + d"
lines_list1 = []
lines_list1 = input_lines_to_list(text, lines_list1)
lines_list2 = []
lines_list2 = input_lines_to_list(text, lines_list2)
If I use this input_lines_to_list() two times it does not work too... Even If I use it first and then a simple input it does not work.
Anyone knows a way around? Thanks!
PS: All of these methods work well if I use it for only one input use.