![图片[1]-Python如何统计行数-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5e8700d2b3a16575.jpg)
Python如何统计行数
方法一:
count=len(open(filepath,'r').readlines())
这种方法简单,但是可能比较慢,当文件比较大时甚至不能工作。
方法二:
可以利用enumerate(),统计文件函数:
count=0 forindex,lineinenumerate(open(filepath,'r')): count+=1 printcount原文来自:https://www.py.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

![图片[1]-Python如何统计行数-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5e8700d2b3a16575.jpg)
Python如何统计行数
方法一:
count=len(open(filepath,'r').readlines())
这种方法简单,但是可能比较慢,当文件比较大时甚至不能工作。
方法二:
可以利用enumerate(),统计文件函数:
count=0 forindex,lineinenumerate(open(filepath,'r')): count+=1 printcount原文来自:https://www.py.cn
暂无评论内容