Ⅰ 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)