python-';状态';对象没有属性';下';
这会给出一个错误AttributeError:“Status”对象在函数tweet=tweet.lower()上没有属性“lower”您认为tweet应该是什么?它应该作为字符串读取,但它作为列表读取python-';状态';对象没有属性';下';,python,python-3.x,Python,Python 3.x,这会给出一个错误AttributeError:“Status”对象在函数tweet=tweet.lower()上没有属性“lower”您认为tweet应该是什么?它应该作为字符串读取,但它作为列表读取 import re from nltk.tokenize import word_tokenize from string import punctuation from nltk.corpus import stopwords from nltk import pu
import re
from nltk.tokenize import word_tokenize
from string import punctuation
from nltk.corpus import stopwords
from nltk import punkt
class pre:
def __init__(self):
self._stopwords=set(stopwords.words('english')+list(punctuation)+['AT_USER','URL'])
def processtweets(self,list1):
processedtweets=[]
for tweet in list1:
processedtweets.append((self._processtweet(tweet["text"]),tweet["label"]))
return processedtweets
def _processtweet(self, tweet):
tweet=tweet.lower()
tweet=re.sub('((www\.[^s]+)|(https?://[^s]+))','URL',tweet)
tweet=re.sub('@[^s]+','AT_USER',tweet)
tweet=re.sub(r'#([^\s]+)',r'\1',tweet)
#r is used to not excape any character
tweet=word_tokenize(tweet)
#tokenized the tweet into the list of words
return [word for word in tweet if word not in self._stopwords]