Amanda
Amanda

Reputation: 12747

Why are "dictionary" and "keys" not defined in python?

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

Answers (1)

NPE
NPE

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

Related Questions