Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I skip first line reading from stdin?

Tags:

python

stdin

 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?

like image 902
Özlem Avatar asked Jul 17 '14 06:07

Özlem


People also ask

How do you skip the first line of a file in Python?

In Python, while reading a CSV using the CSV module you can skip the first line using next() method.

How do you stop read stdin in Python?

Ctrl d closes the standard input (stdin) by sending EOF.

Can you read from stdin?

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.

Is SYS Stdin readline faster than input?

stdin. readline() is the fastest one when reading strings and input() when reading integers.


1 Answers

infile = sys.stdin
next(infile) # skip first line of input file
for line in infile:
     if not line:
         break
     fields = line.split('#')
     ...
like image 135
John La Rooy Avatar answered Sep 18 '22 16:09

John La Rooy