while 1:
try:
#read from stdin
line = sys.stdin.readline()
except KeyboardInterrupt:
break
if not line:
break
fields = line.split('#')
...
How can I skip first line reading from stdin
?
In Python, while reading a CSV using the CSV module you can skip the first line using next() method.
Ctrl d closes the standard input (stdin) by sending EOF.
Using input() function to read stdin data We can also use Python input() function to read the standard input data. We can also prompt a message to the user. Here is a simple example to read and process the standard input message in the infinite loop, unless the user enters the Exit message.
stdin. readline() is the fastest one when reading strings and input() when reading integers.
infile = sys.stdin
next(infile) # skip first line of input file
for line in infile:
if not line:
break
fields = line.split('#')
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With