dict AttributeError only when accessing via dot operator

Viewed 1663

So I am creating a dict like this:

request = {"method": "get"}

and when I try to list the attributes with

print list(request.keys())

I get what I'd expect:

['method']

And I can access the method attribute with

print request['method']

and I get what I'd expect:

get

But if I try to

print request.method

I get an error

AttributeError: 'dict' object has no attribute 'method'

Why am I getting an error with a . but not when I use square brackets?

3 Answers
Related