diff --git a/docs/usage/advanced_usage.rst b/docs/usage/advanced_usage.rst index fac35c2..32334c0 100644 --- a/docs/usage/advanced_usage.rst +++ b/docs/usage/advanced_usage.rst @@ -62,7 +62,12 @@ with a status update. # Assume you are working with a JPEG from PIL import Image - from StringIO import StringIO + try: + # Python 3 + from io import StringIO + except ImportError: + # Python 2 + from StringIO import StringIO photo = Image.open('/path/to/file/image.jpg') @@ -98,7 +103,7 @@ That being said, Twython offers a generator for search results and can be access results = twitter.cursor(twitter.search, q='python') for result in results: - print result + print(result) Manipulate the Request (headers, proxies, etc.) ----------------------------------------------- diff --git a/docs/usage/special_functions.rst b/docs/usage/special_functions.rst index 97e674c..cde8f99 100644 --- a/docs/usage/special_functions.rst +++ b/docs/usage/special_functions.rst @@ -25,7 +25,7 @@ The Old Way results = twitter.search(q='twitter') if results.get('statuses'): for result in results['statuses']: - print result['id_str'] + print(result['id_str']) The New Way ^^^^^^^^^^^ @@ -39,7 +39,7 @@ The New Way results = twitter.cursor(twitter.search, q='twitter') for result in results: - print result['id_str'] + print(result['id_str']) Another example: @@ -47,7 +47,7 @@ Another example: results = twitter.cursor(t.get_mentions_timeline) for result in results: - print result['id_str'] + print(result['id_str']) HTML for Tweet @@ -66,7 +66,7 @@ This function takes a tweet object received from the Twitter API and returns an include_rts=True) for tweet in user_tweets: tweet['text'] = Twython.html_for_tweet(tweet) - print tweet['text'] + print(tweet['text']) The above code takes all the tweets from a specific users timeline, loops over them and replaces the value of ``tweet['text']`` with HTML. diff --git a/docs/usage/streaming_api.rst b/docs/usage/streaming_api.rst index 8b21c70..4d6c1c3 100644 --- a/docs/usage/streaming_api.rst +++ b/docs/usage/streaming_api.rst @@ -27,10 +27,10 @@ Now set up how you want to handle the signals. class MyStreamer(TwythonStreamer): def on_success(self, data): if 'text' in data: - print data['text'].encode('utf-8') + print(data['text']) def on_error(self, status_code, data): - print status_code + print(status_code) # Want to stop trying to get data because of the error? # Uncomment the next line!