Ⅰ python编程 文件操作
Ⅱ python统计文本中有多少行
写一个文本统计的脚本:计算并打印有关文本文件的统计数据,包括文件里包含多少个字回符、行、答单词数,以及前10个出现次数最多的单词按顺序排列
import time
keep=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ','-',"'"]
stop_words=['the','and','i','to','of','a','you','my','that','in','she','he','her','his','it','be','was','had']
def normalize(s):
result=''
for c in s.lower():
if c in keep:
result+=c
Ⅲ Python 计算一个文件中有多少行即读取文件行数
with open(file) as f:
text=f.read()
length=len(text.splitlines())
Ⅳ python 统计一个txt文档有多少行
f=open('a.txt','r')
cont=f.readlines()
print len(cont)