python读取文件同时输出行号和内容
file = open('file.txt','r') for (num,value) in enumerate(file): print "line number",num,"is:",value file.close() #输出结果: line number 0 is: Hello, world. line number 1 is: I'm a simple text file. line number 2 is: Read me !
python读取文件同时输出行号和内容
file = open('file.txt','r') for (num,value) in enumerate(file): print "line number",num,"is:",value file.close() #输出结果: line number 0 is: Hello, world. line number 1 is: I'm a simple text file. line number 2 is: Read me !