Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python-';状态';对象没有属性';下';_Python_Python 3.x - Fatal编程技术网

python-';状态';对象没有属性';下';

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

这会给出一个错误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 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]