Search code examples
pythonapiwolframalphastopiteration

Python Wolfram Alpha API: StopIteration


How can I avoid the stopiteration error? I am unaware of any functions or loops that the code may be iterating through.

import wolframalpha

client = wolframalpha.Client('My Key is Goes Here')
res = client.query('pi')

print next(res.results).text

Solution

  • I've never used wolframalpha, but this looks like it should be

    for result in res.results:
        print result.text
    

    Edit: I've now installed wolframalpha and I see that that query (and the others I have tried) have no results in res.results. Instead, they have pods. You can iterate through pods as in the docs:

    for pod in res.pods:
        print '{p.title}: {p.text}'.format(p=pod)