考虑从“pydantic”包派生的这个数据类:
from typing import List
from pydantic import BaseModel
class Bucket(BaseModel):
setting: List[str]
fight_1: List[int]
cause_1: List[str]
让我们my_bucket
成为一个实例Bucket
:
my_bucket = Bucket(setting = ['some_value'], fight_1 = [0], cause_1 = ['other_value'])
基本上我希望能够做到
my_bucket['setting']
并返回['some_value']
,但我得到:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-18-cacbdc1698e9> in <module>
----> 1 my_bucket['setting']
TypeError: 'Bucket' object is not subscriptable