0

我编写了一个使用 Twython 与 twitter 交互的 python 脚本。它将关注者列表下载到一个变量(关注者)中,并将我关注的人列表下载到另一个变量(朋友)中。然后它应该自动跟随所有关注我但我尚未关注的人。

for fol in followers:
    if fol not in friends:
        twitter.create_friendship(fol)

我得到的错误是只twitter.create_friendship需要一个参数,但它被赋予了两个。我看不出它是如何被赋予两个论点的,我只能看到一个。

4

1 回答 1

5

create_friendship()是一个绑定方法,这意味着它将只接受self参数。它不接受任何其他位置参数,但您正在传入fol,现在给它两个参数(selffol)。

该方法应改为传递关键字参数:

twitter.create_friendship(user_id=fol)

iffol是用户 ID,或

twitter.create_friendship(screen_name=fol)

iffol是一个屏幕名称。

于 2014-10-06T13:14:10.180 回答