首页 > 编程 > Python > 正文

python 读文件 和行号

2019-11-08 01:53:41
字体:
来源:转载
供稿:网友

python 读文件 和行号 代码如下:

file = open('file.txt','r')for (num,value) in enumerate(file):    PRint "line num is: ",num,"content:",valuefile.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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表