I have some code looks like this:
while line != '' and line != 'STOP ME':
line = raw_input("")
buf.append(line+'\n')
sys.stdin.flush()
print raw_input("Input1:")
print raw_input("Input2:")
The problem is, if the user copy and paste the data like this
line1
line2
STOP ME
"empty line"
"empty line"
Some junk text
My raw_input will be overflowed with junk text after "STOP ME". Is there a way to avoid it?
May be you don’t need
raw_inputhere? You can usesys.stdinfile-like object. For examplesys.stdin.readmethod.Or you can use somthing like this:
to get data before
STOP MEline.