该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import os,string,codecs
import sys,time
def readfile():
wordlist[]
aimfilmraw_input(anter your file nema :)
baseopen(aimfilm,r)
baseinfobase.readlines()
tagfopen(tag.txt,r)
tagfinfotagf.readlines()
for i in tagfinfo:
tagsi.split( )
for i in baseinfo:
wordsi.split( )
for word in words:
if word ! \\tand word ! \\n and word! and word ! and word>2:
wordword.replace(\\t,)
wordword.replace(\\n,)
wordword.replace( ,)
wordword.replace(.\\n,)
if word!:
wordlist.append(word)
tags[.,",,,!,?,(,)]
for x in range(len(tags)):
#global tags
tagtags[x]
for k in range(len(wordlist)):
if tag in wordlist[k]: #用符号分割
wordswordlist[k].split(tag)
del wordlist[k]
for j in range(len(words)): #去掉判断后的空字符
if words[j]!:
wordlist.append(words[j])
base.close()
tagf.close()
return wordlist
def getstr(word,count,allwordnum):
countstrword--------str(count)#--------str(allwordnum)
return countstr
if __name__"__main__":
wordcnt{}
wordlistreadfile()
wordlistallwordlist
allwordnumlen(wordlistall)
outdataopen(count.txt,w)
print ******************************************
print ******************************************
print(u"start......")
print------------------------------------------------------------------------
for i in wordlistall:
if i in wordcnt:
wordcnt[i]1
else:
wordcnt[i]1
for word,cnt in wordcnt.iteritems():
print word--------str(cnt)#--------str(allwordnum)
outdata.write(getstr(word,cnt,allwordnum)\n)
print------------------------------------------------------------------------
print(u"finish")
#print(upress any key to exit)
outdata.close()
词频统计有的文件报这个错小白求教
Traceback (most recent call last):
File "cptj.py", line 50, in
wordlistreadfile()
File "cptj.py", line 33, in readfile
if tag in wordlist[k]: #用符号分割
IndexError: list index out of range
【文章转自中东服务器 http://www.558idc.com/dibai.html欢迎留下您的宝贵建议】