处理数据时候,需要得到数据所在和行号,使用enumerate时便捷的方法:
1 file = open('file.txt','r') 2 for (num,value) in enumerate(file): 3 print "line num is: ",num,"content:",value 4 file.close()