list_of_files = glob.glob('C:/Users/user/Desktop/speech./*.txt')
for file_name in list_of_files:
with open(file_name, 'rb') as f:
text = f.read()
seglist = jieba.cut(text, cut_all=False)
with open(file_name, 'w') as f:
w = csv.writer(f)
w.writerows(seglist)
似乎需要将字节发送到cut而不是file对象
请尝试以下代码:
从我从source code as example和jieba.cut definition中读到的,
jieba.cut
似乎需要字符串作为参数。在但您给出的是
file
的一个实例。在根据我所见修正了这个问题。(
FI.read()
是修复)。在顺便说一句,不要调用像
FI
/FO
这样的变量,这是常量或类的有效名称,但不是变量。在Explicit比implicit好:更喜欢这样的东西:
file_output
&;file_input
。在相关问题 更多 >
编程相关推荐