-3
我要選擇那些句子包含了一些連詞mentioned.But我得到一個錯誤:在Excel工作表中查找的話,「STR」不支持緩衝區接口
Traceback (most recent call last):
File "positive_process3.py", line 14, in <module>
if word in text:
TypeError: 'str' does not support the buffer interface.
我的代碼是:
import xlrd
from xlrd import open_workbook
import xlwt
wb = open_workbook("C:/Users/SA769740/Desktop/result2/pos.xlsx")
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Sheet 1")
wordSet = [' for ', ' so ',' since ', ' Since ', ' because ', ' as ', ' As ', ' due to ', ' Due to ']
count=1
for sheet in wb.sheets():
for row in range(sheet.nrows):
text = ((sheet.cell(row,2).value).encode("utf-8"))
l = ""
for word in wordSet:
if word in text:
l += (word+" ")
sheet1.write(row,0,sheet.cell(row, 0).value)
sheet1.write(row,3, l)
sheet1.write(row,4,count)
sheet1.write(row,5,value)
count += 1
book.save('C:/Users/SA769740/Desktop/result2/pos_reviews_process3.xls')
我使用Python 3.4.3
請編輯您的問題並修復此問題。現在你的代碼是無效的Python。 –
你確定**你正在使用Python 2嗎?該異常強烈建議您使用Python 3.「text」由Unicode編碼,「wordSet」中的「word」爲純字符串文字。我只能在Python 3上重現您的異常。 –
可能的重複http://stackoverflow.com/questions/5471158/typeerror-str-does-not-support-the-buffer-interface – cdarke