python3利用jieba分词

没有人一开始就能想清楚,只有做起来,目标才会越来越清楚。——马克·扎克伯格

下载jieba

pip3 install jieba

在这里插入图片描述

创建测试文件

jiebaDemo.txt
在这里插入图片描述

编写代码

在这里插入图片描述

import jieba

filepath = input("input your path:")

with open(filepath,encoding='utf-8') as f:
    words = jieba.lcut(f.read())
    print(words)

执行结果

得到的结果是一个list列表
在这里插入图片描述

封装为一个函数

import jieba

def jiebaFunc(filepath):
	with open(filepath,encoding='utf-8') as f:
	    words = jieba.lcut(f.read())
	    print(words)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章