0

I want to count the number of the result JSON objects: how can I do?

I have this function: (the problem is in "for i in r:")

import urllib
import json
from classes import ricerca_IMDB

def search_IMDB (titolo):
    sito='http://www.omdbapi.com/?s='+titolo

    r=0
    r=json.loads(urllib.urlopen(sito).read())

    i=0
    filmList = []
    try:
        for i in r:
            filmList.append(ricerca_IMDB(r['Search'][i]['Title'], r['Search'][i]['Year'], r['Search'][i]['imdbID']))
    except:
        filmList = []

    return filmList
1
  • 3
    'the problem is in'.. but what is exactly your problem? Do you get an error? Remove the bare try except (never a good idea) and tell us what the traceback is. Commented Dec 11, 2012 at 22:01

1 Answer 1

2

You've completely botched up your type handling. Iterating over a sequence yields elements.

for i in r['Search']:
  filmList.append(ricerca_IMDB(i['Title'], i['Year'], i['imdbID']))
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.