This commit is contained in:
yumoqing 2024-04-17 14:47:37 +08:00
parent ec56a07a8b
commit a721f00a68

View File

@ -25,7 +25,8 @@ class DictObject(dict):
实现点操作符访问字典中的键值对 实现点操作符访问字典中的键值对
""" """
try: try:
return self.__DOitem(self[attr]) v = self.__DOitem(self[attr])
self[attr] = v
except KeyError: except KeyError:
return None return None
@ -53,8 +54,9 @@ class DictObject(dict):
def __getitem__(self, key): def __getitem__(self, key):
try: try:
v = super().__getitem__(key) v = self.__DOitem(super().__getitem__(key))
return self.__DOitem(v) self[key] = v
return v
except KeyError: except KeyError:
return None return None
@ -65,8 +67,11 @@ class DictObject(dict):
self[attr] = value self[attr] = value
def get(self, k, defv=None): def get(self, k, defv=None):
v = super().get(k, defv) try:
return self.__DOitem(v) v = self.__getitem__(k)
return v
except:
return defv
def copy(self): def copy(self):
return self.__DOitem(super().copy()) return self.__DOitem(super().copy())