我正在使用nltk包中的Vader。 我已經導入我的數據集以下維德教程:AttributeError:'list'對象沒有'text'屬性
list = []
for line in open("C:\Users\Luca\Desktop\Uni\Tesi\PythonTest\paolo.txt","r").readlines():
for value in line.split(","):
list.append(value)
然後我創建了函數刪除標點:
def _words_only(self):
text_mod = REGEX_REMOVE_PUNCTUATION.sub('', self.text)
words_only = text_mod.split()
words_only = [word for word in words_only if len(word) > 1]
return words_only
但是當我嘗試使用「字只有」我的功能得到這個錯誤
AttributeError Traceback (most recent call last)
<ipython-input-14-cbc12179c890> in <module>()
----> 1 _words_only(list)
<ipython-input-13-68a545bbbaa4> in _words_only(self)
1 def _words_only(self):
----> 2 text_mod = REGEX_REMOVE_PUNCTUATION.sub('', self.text)
3 words_only = text_mod.split()
AttributeError: 'list' object has no attribute 'text'
我對Python真的很陌生。這是導入過程中的問題還是其他問題?謝謝你的幫助。
你能分享你的課程嗎? 您正在發送列表作爲您的words_only函數的參數。我想你應該發送字符串不在這裏列表。 –
'_words_only'是班級的一部分嗎? – 2016-07-06 09:38:07