get 一个操作word包:安装python-docx:pip install python_docx
废话不多说,直接上源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import jieba#jieba很有个性 santi_text = open('./santi.txt').read() cut = jieba.cut(santi_text) get=','.join(cut)#get为str list=get.split(',') word=[] num=[] for i in list: if i in word: num[word.index(i)]+=1 else: word.append(i) num.append(1) fp=open("reslut.xls","w") for i in word: fp.write(i+'\t'+str(word.index(i)+'\n')) fp.close()