2013-04-28 12 views
1

이것은 내 코드가 아니며 원하는 작업을 수행하는 (또는 수행해야하는) 인터넷에서 발견 된 모듈입니다.왜 이것이 "잘못된 구문"입니까?

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 

파이썬 쉘은 내가 그렇게 작동하지 않는 이유를 아무 생각이 거의 파이썬을 알고 오류가 하나 개의 라인 1을 나타냅니다 보인다.

+4

어떤 버전의 파이썬을 사용하고 있습니까? > = 3.0이면'print()'를 사용하십시오 (이제는 함수입니다) – lifetimes

+0

그 비트를 정렬했습니다. 지금 나는 "ImportError : 모듈에 '요청'이라는 이름이 없습니다." – user1765369

+0

[이 답변 확인] (http://stackoverflow.com/questions/11994337/need-help-installing-requests-for-python-3), look 'requests' 모듈로 문제를 해결할 수있는 것처럼 말입니다. – raina77ow

답변

4

이 스 니펫은 Python 2.x이지만 Python 3.x (print은 이제 적절한 기능 임)로 작성되었습니다. 이 문제를 해결하려면 print SomeExpprint(SomeExpr)으로 대체하십시오.

이 차이점은 3.x의 다른 변경 사항과 함께 detailed description입니다.