Reputation: 12747
I'm great with PHP and trying to learn Python. So forgive me if I'm trying to translate functions too literally, but here's what I have:
import json
import urllib
url='http://www.example.com/sample.json'
f = urllib.urlopen(url)
data = json.loads(f.read())
for item in data:
for entry in item:
print dictionary.keys(entry)
I know that item
has type dict because I did print type(item)
. But when I try to run the code above, I get NameError: name 'dictionary' is not defined
-- do I need to import a library that defines dictionary functions? If so, which library?
Upvotes: 1
Views: 3941
Reputation: 500595
Write
print entry.keys()
instead of
print dictionary.keys(entry)
I'd recommend having a look at the tutorial and the library reference.
Upvotes: 9