小白基础代码专用
import
sys
sys.path.append(
'../'
)
import
jieba
import
jieba.analyse
from
optparse
import
OptionParser
USAGE
=
"usage: python extract_tags.py [file name] -k [top k]"
parser
=
OptionParser(USAGE)
parser.add_option(
"-k"
, dest
=
"topK"
)
opt, args
=
parser.parse_args()
if
len
1
:
(USAGE)
sys.exit(
1
)
file_name
=
args[
]
if
opt.topK
is
None
:
topK
=
10
else
:
topK
=
int
(opt.topK)
content
=
open
(file_name,
'rb'
).read()
tags
=
=
topK)
(
"\n"
.join(tags))
领取专属 10元无门槛券
私享最新 技术干货