Reputation: 137
I hope this is not a duplicate, I checked all suggested topics and couldn't find what I am looking for or is working.
I want to input as many strings as I want (amount not predefined) and as soon as an empty line occurs, the input should stop. What I've tried so far with no success:
while True:
inp = raw_input()
if inp.strip() == "":
break
;
while True:
inp = sys.stdin.readline()
if inp == '\n':
break
;
while raw_input().strip()!="":
inp = raw_input()
and such combinations of everything I could find on the Internet. Nothing works so far, any help would be very appreciated!
Upvotes: 0
Views: 1600
Reputation: 2305
You can check to see if the length of the line is 1 and the ascii character is 10 which is Line feed using ord
you can break it then.
Upvotes: -1
Reputation: 531055
The two-argument form of iter
is almost made for this:
for line in iter(raw_input, ""):
print "You input", line
Upvotes: 3