I've got a code fragment:
#!/usr/bin/env python
import sys
num_lst = []
num_circ = []
while True:
print "Type number or [e]nd operation"
inpt = sys.stdin.readline()
print inpt
if inpt == 'e':
sys.stdin.flush()
print "\n"
break
else:
num_lst.append(inpt)
sys.stdin.flush()
for i in num_lst:
if isinstance(i, int):
num_circ.append(i)
else:
pass
print "Typed %d number\n" % len(num_circ)
The part where the
num_lst.append(inpt)
function is invoked, works not as i'd like to.
That chunk works fine:
print "Type number or [e]nd operation"
inpt = sys.stdin.readline()
print inpt
the input is accepted and printed out, but here:
else:
num_lst.append(sys.__stdin__)
sys.stdin.flush()
for i in num_lst:
if isinstance(i, int):
num_circ.append(i)
else:
pass
print "Typed %d number\n" % len(num_circ)
this chunk of code doesn't work, because no value is appended into num_lst list.
I'm quiet disoriented. How to append the sys.stdin buffer into list in most pythonic way?