将tab换成空格,使用is判断对象是否为None

This commit is contained in:
cloudaice 2013-05-10 22:55:04 +02:00
parent 7ce5116a93
commit a2d2078465

View File

@ -5,29 +5,26 @@ import jieba
import jieba.analyse import jieba.analyse
from optparse import OptionParser from optparse import OptionParser
USAGE ="usage: python extract_tags.py [file name] -k [top k]" USAGE = "usage: python extract_tags.py [file name] -k [top k]"
parser = OptionParser(USAGE) parser = OptionParser(USAGE)
parser.add_option("-k",dest="topK") parser.add_option("-k", dest="topK")
opt, args = parser.parse_args() opt, args = parser.parse_args()
if len(args) <1: if len(args) < 1:
print USAGE print USAGE
sys.exit(1) sys.exit(1)
file_name = args[0] file_name = args[0]
if opt.topK==None: if opt.topK is None:
topK=10 topK = 10
else: else:
topK = int(opt.topK) topK = int(opt.topK)
content = open(file_name, 'rb').read()
content = open(file_name,'rb').read() tags = jieba.analyse.extract_tags(content, topK=topK)
tags = jieba.analyse.extract_tags(content,topK=topK)
print ",".join(tags) print ",".join(tags)