python读取文件行号和内容的便捷方法

处理数据时候,需要得到数据所在和行号,使用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()

 

posted @ 2018-10-12 10:20  今夜无风  阅读(6184)  评论(0编辑  收藏  举报