想打开一个csv文件,把其中的内容通过jieba分词分开。 代码如下:
import jieba import csv
with open(r'C:\Users\robin\Desktop\test1.csv',newline='') as f: a = csv.reader(f)
sl=jieba.cut(a) print('/'.join(sl))
报错如下: C:\Python34\python.exe "E:/Python Project/Test/fenci.py" Traceback (most recent call last): File "E:/Python Project/Test/fenci.py", line 11, in <module> print('/'.join(sl)) File "C:\Python34\lib\site-packages\jieba_init_.py", line 282, in cut sentence = strdecode(sentence) File "C:\Python34\lib\site-packages\jieba_compat.py", line 37, in strdecode sentence = sentence.decode('utf-8') AttributeError: '_csv.reader' object has no attribute 'decode'
求教
Sign in to make a reply
赵彬RobinZ
想打开一个csv文件,把其中的内容通过jieba分词分开。 代码如下:
import jieba import csv
with open(r'C:\Users\robin\Desktop\test1.csv',newline='') as f: a = csv.reader(f)
sl=jieba.cut(a) print('/'.join(sl))
报错如下: C:\Python34\python.exe "E:/Python Project/Test/fenci.py" Traceback (most recent call last): File "E:/Python Project/Test/fenci.py", line 11, in <module> print('/'.join(sl)) File "C:\Python34\lib\site-packages\jieba_init_.py", line 282, in cut sentence = strdecode(sentence) File "C:\Python34\lib\site-packages\jieba_compat.py", line 37, in strdecode sentence = sentence.decode('utf-8') AttributeError: '_csv.reader' object has no attribute 'decode'
求教