python - How to skip reading first line from file when using fileinput method -


i doing read file:

import fileinput line in fileinput.input('/home/manish/java.txt'):   if not fileinput.isfirstline(): ...             data = proces_line(line); ...             output(data) 

it throwing error proces_line not defined.

traceback (most recent call last):   file "<stdin>", line 3, in <module> nameerror: name 'proces_line' not defined 

i have read data line line , store in list, each line being separate element of list.

you can skip first line follows:

import fileinput  def output(line):     print(line)   fi = fileinput.input('/home/manish/java.txt') next(fi)    # skip first line  line in fi:     output(line) 

this avoids having test first line each time in loop.


to store each of lines list, following:

import fileinput  fi = fileinput.input('/home/manish/java.txt') next(fi)    # skip first line output = list(fi) fi.close()  print(output) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -