【问题标题】:python-twitter program only runs in shellpython-twitter 程序仅在 shell 中运行
【发布时间】:2013-02-04 16:28:16
【问题描述】:

我是 Twitter API 和 python-twitter 的新手。我正在尝试运行下面的简单程序:

import twitter
api = twitter.Api()
user = 'GoldmanSachs'
statuses = api.GetUserTimeline(screen_name=user)
for s in statuses:
    print s

当我在 Python Shell 中运行程序时,我会得到下面的预期输出。

{"created_at": "2013 年 1 月 28 日星期一 22:21:14 +0000", "favorited": false, “id”:296020134164836353,“retweet_count”:2,“转推”:假, “来源”:“网络”,“文本”:“ICYMI:华尔街日报的达沃斯直播博客与 FX de Mallmann 谈欧洲公司在债券市场筹集资金。 http://t.co/hCLGBOOy", ....}

但是,当我尝试保存程序然后运行它时,我得到一个 AttributeError:

Traceback (most recent call last):
  File "\twitter.py", line 1, in <module>
    import twitter
  File "\twitter.py", line 6, in <module>
    api = twitter.Api()
AttributeError: 'module' object has no attribute 'Api'

任何关于为什么会发生这种情况的想法将不胜感激。

【问题讨论】:

标签: python twitter python-twitter


【解决方案1】:

您很可能将您的程序命名为twitter.py,它的影子是python-twitter。重命名脚本。

【讨论】:

  • 我更改了程序的名称,我得到了同样的错误:(
  • 还有什么叫 twitter 的吗?
  • 找到了!你说得对,那里还有另一个 twitter.py 程序。我觉得自己像个菜鸟。
猜你喜欢
  • 2011-11-17
  • 2021-02-26
  • 1970-01-01
  • 2011-08-02
  • 1970-01-01
  • 1970-01-01
  • 2014-05-03
  • 2014-02-09
  • 1970-01-01
相关资源
最近更新 更多