453423 发表于 2016-6-23 09:47:10

python读取特定的行

fr = open(filename)
for line in fr.readlines():
    if line.startswith("#"):
      continue
    else:
      ## do something with line
         
## could use fr.readlines()from second line

import linecache
content_list = linecache.getlines(filename)   ## Here using getlines

fourth_line = linecache.getline(filename, 4)      ## Here using getline
## the above method is simpler.


页: [1]
查看完整版本: python读取特定的行