简体   繁体   English

Pattern3 代码在 Python3 中对我不起作用(但我知道该代码对其他人有效),这与我使用的是 Mac 有关系吗?

[英]Pattern3 code not working for me in Python3 (but I know the code works for others), does it matter that I'm using a Mac?

I continue to get the error, "'<=' not supported between instances of 'NoneType' and 'int'", but none of the fellow students are receiving this error.我继续收到错误消息“'<=' not supported between instances of 'NoneType' and 'int'”,但没有同学收到此错误。 This code was provided to us, so I know I didn't do something wrong.这段代码是提供给我们的,所以我知道我没有做错什么。 My only guess is that it needs something different when it is run on a mac vs windows?我唯一的猜测是它在 Mac 上运行时需要一些不同的东西而不是 windows?

%%time
from pattern.web import Twitter, hashtags
engine = Twitter(language="en")

indexid = set() 
tweets =[]

prev = None
for i in range(5):
    print(i)
    for tweet in engine.search("stock market bull or bear", start=prev, count= 20, cached=False):
        print(f" hashtag = {hashtags(tweet.text)} text = {tweet.text}, author = {tweet.author}, date = {tweet.date} ")
        if len(tweet.text) > 0 and tweet.id not in indexid:
            tweets.append(tweet.text)
            indexid.add(tweet.id)
            prev = tweet.id
print(f"Found {len(tweets)} tweets!" )
print("")

The default to engine.search must be an integer or an id. engine.search的默认值必须是 integer 或 id。 The method is defined as follows:该方法定义如下:

def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=None, cached=False, **kwargs):
    """ Returns a list of results from Twitter for the given query.
        - type : SEARCH,
        - start: Result.id or int,
        - count: maximum 100.
        There is a limit of 150+ queries per 15 minutes.
    """

So in this case, all you need to do is initialize prev to start at 1 , instead of None (which is what is causing your error).所以在这种情况下,您需要做的就是将 prev 初始化为从1开始,而不是None (这是导致错误的原因)。

prev = 1
for i in range(5):
    ...

Which resulted in:结果是:

Found 25 tweets!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的代码不起作用? 我是在 Python3 上使用 pandas 的新手 - Why does my code not work? I'm a novice at working with pandas on Python3 这个 python 代码对我不起作用,我不知道为什么。 告诉我代码是否有问题 - This python code isn't working for me and I do not know why. Tell me if there any promblem with the code 无论我输入哪种文本,代码都有效 - the code works no matter which text I type Python 如何知道从我正在处理的代码中导入,而不是从站点包中导入? - How does Python know to import from the code i'm working on, rather than importing from site-packages? 我试图使用 adaline 学习在 python 中编码的神经元不起作用 - The neuron that I'm trying to code in python using adaline learning is not working 我试图只使用while循环在python中编写此代码,但我不知道它有什么问题? - I'm trying to write this code in python only using while loops, but I don't know what is wrong with it? 代码工作在单元格中单独运行,但是在导入时不起作用 - Code works run Individually in a cell ,But not working when i'm importing it Python-我不知道如何在此代码中最小工作 - Python - I dont know how to min works in this code 我是编码新手,我正在学习 python,我写了一些代码,但有一个函数永远无法工作,原因对我来说并不明显 - I'm new to coding & I'm learning python and I wrote some code but there's a function that never works and the reason isn't that obvious for me 所以我试图以最愚蠢的方式在python3中创建一个嵌套列表,可能是我的代码在第19行给了我“超出范围”索引错误 - So I'm trying to make a nested list in python3 in the dumbest way possible an my code gives me an “Out of Range” index error on line 19
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM