1

This isn't my code, it is a module I found on the internet which performs (or is supposed to perform) the task I want.

print  '{'
for page in range (1,4):
    rand = random.random()
    id = str(long( rand*1000000000000000000 ))
    query_params = { 'q':'a',
        'include_entities':'true', 'lang':'en',
         'show_user':'true',
         'rpp': '100', 'page': page,
         'result_type': 'mixed',
         'max_id':id}
    r = requests.get('http://search.twitter.com/search.json',
                 params=query_params)
    tweets = json.loads(r.text)['results']
    for tweet in tweets:
        if tweet.get('text') :
            print  tweet
print  '}'
print

The Python shell seems to indicate that the error is one Line 1. I know very little Python so have no idea why it isn't working.

4
  • 4
    Which version of python are you using? If >= 3.0 use print() (it is now a function) Commented Apr 28, 2013 at 16:36
  • That sorted.. that bit. Now I'm getting "ImportError: No module named 'requests'" Commented Apr 28, 2013 at 16:39
  • Check this answer, looks like it may solve your problem with requests module. Commented Apr 28, 2013 at 16:42
  • 1
    @user1765369: You probably don't have a module named request installed, but please: one question per post. Commented Apr 28, 2013 at 16:43

1 Answer 1

4

This snippet is written for Python 2.x, but in Python 3.x (where print is now a proper function). Replace print SomeExp with print(SomeExpr) to solve this.

Here's a detailed description of this difference (along with other changes in 3.x).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.