fr = open(filename) for line in fr.readlines(): if line.startswith("#"): continue else: ## do something with line ## could use fr.readlines()[1:] from second line import linecache content_list = linecache.getlines(filename)[1:] ## Here using getlines fourth_line = linecache.getline(filename, 4) ## Here using getline ## the above method is simpler.
时间: 2024-10-05 19:47:05