'''''
Created on Dec 21, 2012
Python 读取UTF-8文件
统计文件的行数目
@author: liury_lab
'''
# -*- coding: utf-8 -*-
import codecs
# 对较小的文件,最简单的方法是将文件读入一个行列表中,
# 然后计算列表的长度即可
count = len(codecs.open('d:/FreakOut.cpp', 'rU', 'utf-8').readlines())
print(count)
# 对较大的文件,可循环计数
count = -1
for count, line in enumerate(codecs.open('d:/FreakOut.cpp', 'rU', 'utf-8')):
pass
count += 1
print(count)
# 对于像windows结束标记有'\n'的,还可以有如下办法:
count = 0
the_file = codecs.open('d:/FreakOut.cpp', 'rb', 'utf-8')
while (True):
buffer = the_file.read(8192*1024)
if not buffer:
break
count += buffer.count('\n')
count += 1
the_file.close()
print(count)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有