沒有人一開始就能想清楚,只有做起來,目標纔會越來越清楚。——馬克·扎克伯格
下載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)