python 读文件 和行号 代码如下:
file = open('file.txt','r')
for (num,value) in enumerate(file):
print "line num is: ",num,"content:",value
file.close()
with open('file.txt','r') as f:
for (num,value) in enumerate(file):
print "line num is: ",num,"content:",value
-------output---------
line number is: 0 content: start line
line number is: 1 content: test
line number is: 2 content: end