【问题标题】:TypeError: can only concatenate tuple (not "str") to tuple using "-filter:retweets" in PythonTypeError:只能在 Python 中使用“-filter:retweets”将元组(不是“str”)连接到元组
【发布时间】:2021-07-01 00:34:57
【问题描述】:

我是 Python 新手,目前正在尝试使用这些关键词处理一些推文。任何帮助将不胜感激!

# Define the search term and the date_since date as variables
search_words = ("#breastcancer", "Breast Cancer")
date_since = "2020-03-01"    
new_search = (search_words + "-filter:retweets")
new_search

TypeError                                 Traceback (most recent call last)
<ipython-input-19-c3105fd62a2e> in <module>
----> 1 new_search = (search_words + "-filter:retweets")
      2 new_search

TypeError: can only concatenate tuple (not "str") to tuple

【问题讨论】:

  • search_words 是一个元组吗?如果是这样,那么错误正确地指出您不能连接元组和字符串。你期待这行代码做什么?
  • 你能告诉我们search_words包含什么吗?

标签: python tweepy


【解决方案1】:

要使用 tweepy 搜索多个单词,您应该像这样使您的搜索词可变:

search_terms = ('#breastcancer OR Breast Cancer')

感谢这篇文章: Search term intersection and union using Python Tweepy

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多