如何查看python方法的参数(和类型)?

2024-09-28 05:25:36 发布

您现在位置:Python中文网/ 问答频道 /正文

$ py twitterDump2.py 
Traceback (most recent call last):
  File "twitterDump2.py", line 30, in <module>
    stream=tweepy.Stream(username,password,listener)
TypeError: __init__() takes exactly 3 arguments (4 given)

我的代码:

^{pr2}$

Tags: inpymoststreamlineusernamecallfile
2条回答

-init\uuu的第一个参数通常是self,因此它希望您只传递两个参数。在

令人惊讶的tweepy.streaming.py代码建议:

class Stream(object):

    host = 'stream.twitter.com'

    def __init__(self, auth, listener, **options):
        self.auth = auth
        self.listener = listener

身份验证的创建方式如下:

^{pr2}$

你的代码应该是这样的

^{3}$

请参见代码:http://github.com/joshthecoder/tweepy/blob/master/tweepy/streaming.py

给出了为什么PY功能不起作用的原因。在

要查看哪些参数,请键入:

help(tweepy.Stream)

这将提供Stream类需要的参数。在

以下内容仅供参考:

def __init__(self, auth, listener, **options)

options获取一个字典,该字典使用**运算符传递关键字参数。在

相关问题 更多 >

    热门问题