user1765369
user1765369

Reputation: 1395

Why is is this "Invalid syntax" in Python?

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.

Upvotes: 1

Views: 573

Answers (1)

raina77ow
raina77ow

Reputation: 106385

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).

Upvotes: 4

Related Questions