【发布时间】:2023-04-07 01:05:01
【问题描述】:
所以我正在创建一个这样的字典:
request = {"method": "get"}
当我尝试使用
列出属性时print list(request.keys())
我得到了我所期望的:
['method']
我可以通过
访问method属性
print request['method']
我得到了我所期望的:
get
但如果我尝试
print request.method
我收到一个错误
AttributeError: 'dict' 对象没有属性 'method'
为什么我在使用 . 时收到错误,但在使用方括号时却没有?
【问题讨论】:
标签: python dictionary