简体   繁体   中英

Python Twitter bot works from interpreter but not when run as program?

answered

I've written a toy program to emulate a particular Twitter user (scraped their tweets, ran them through NLTK, wrote a generator, etc). Everything works with the program and I can print to terminal just fine.

Now, I'm trying to hook it up to Twitter. I'm using Python Twitter Tools ( http://mike.verdone.ca/twitter/#screenshots ). At the beginning I have one of these with my info:

t = Twitter(
            auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                       CONSUMER_KEY, CONSUMER_SECRET)
           )

And at the end I have one of these:

tweet = choice (possTweets)
t.statuses.update(status=tweet)

Now, here's the odd bit. If I run my program through the interpreter (meaning I enter python and type in the code manually) like so:

>>> import twitter
>>> from twitter import *
>>> t = Twitter(
            auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
                       CONSUMER_KEY, CONSUMER_SECRET)
           )
>>> t.statuses.update(status="test")

it works fine, and updates the Twitter account. If, however, I run myProgram.py in the terminal, I get this:

File "myProgram.py", line 148, in <module>
t.statuses.update(status="test2")
AttributeError: 'tuple' object has no attribute 'statuses'

What am I doing wrong?

Blender帮我解决了 - 我在程序的其他地方使用迭代列表,一旦我切换到tw.statuses它工作正常!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM