0
how to read unknown no. of lines in python
5 Réponses
+ 1
Code :
file = open("filename.txt", "r")
for line in file:
print(line)
file.close()
Output :
>>>
Line 1 text
Line 2 text
Line 3 text
>>>
+ 3
Not sure if this is what you need, but it will read multipline lines of input from the console and only stop if an empty line is entered (probably doesn't work in SoloLearn, but it works in a console). Everything will be stored in the variable c.
c = ''
while True:
ui = input('>>> ').strip()
if ui != '':
c += ui + '\n'
else:
# remove last exit character
c = c[:-1]
break
print(c)
0
not sure what you mean but random module might be one way
0
Sam Pache unknown, but yeah basic principle
0
not from file
how to read directly from console