两段小PYTHON,作啥用的,行内人才懂~~~:(

时间:2023-03-09 21:25:08
两段小PYTHON,作啥用的,行内人才懂~~~:(

哎,作也不是,不作也不是。。。。

下次有更新文件时,直接刷新一次了。

#coding: UTF-8

import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )
#从EXCEL文件中按要求组合动词+名词
import xlrd
xlsfile = r"820.xls"
data = xlrd.open_workbook(xlsfile)
zscy = []
dc = []
mc = []
table = data.sheets()[0]
nrows = table.nrows
for i in range(nrows ):
    if table.row_values(i)[3] == u'专属词语' :
        zscy.append(table.row_values(i)[0])
    if table.row_values(i)[3] == u'动词' :
        dc.append(table.row_values(i)[0])
    if table.row_values(i)[3] == u'名词' :
        mc.append(table.row_values(i)[0])

f = open('test.txt', 'w')
for i in zscy:
    print >>f,i
f.close()

f = open('test2.txt', 'w')

for i in dc:
    for j in mc:
        print >>f,i+j

f.close()
#coding: UTF-8

#所有词去重过滤
file = open("lice.csv")
qc = []
while 1:
    line = file.readline()
    if not line:
        break
    if line not in qc:
        qc.append(line)

f = open('test.csv', 'w')
for i in qc:
    print >>f,i.strip()
f.close()