@@ -64,7 +64,7 @@ def from_dict____(cls, dict_):
64
64
Returns:
65
65
result: the resulting DotDict
66
66
"""
67
- # print(f"fromdict____ dic : {dic }") # Debug
67
+ # print(f"from_dict____ dict_ : {dict_ }") # Debug
68
68
result = DotDict ()
69
69
70
70
for key in dict_ :
@@ -115,33 +115,33 @@ def _mand_init(self, *args, **kwargs):
115
115
116
116
# Set the inherited keys from the custom class level
117
117
if self_type is not DotDict and issubclass (self_type , DotDict ):
118
- class_dict = self_type . __dict__
118
+ class_dir = dir ( self_type )
119
119
120
- for key in class_dict :
121
- key = str (key )
122
- # print(f"_dot_dict_init class_dict {key }: {class_dict[key] }") # Debug
120
+ for name in class_dir :
121
+ name = str (name )
122
+ # print(f"_mand_init class attribute {name }: {getattr(self_type, name) }") # Debug
123
123
124
- if not self_type .is_exc_key____ (key ):
125
- val = class_dict [ key ]
126
- self .set_attr____ (key , val )
124
+ if not self_type .is_exc_key____ (name ):
125
+ val = getattr ( self_type , name )
126
+ self .set_attr____ (name , val )
127
127
# end for
128
128
# end if
129
129
130
130
# Set keys with the key names from the variable arguments
131
131
for arg in args :
132
132
arg = str (arg )
133
- # print(f"_dot_dict_init *args arg: {arg}") # Debug
133
+ # print(f"_mand_init *args arg: {arg}") # Debug
134
134
135
- if not self_type .is_exc_key____ (key ):
135
+ if not self_type .is_exc_key____ (name ):
136
136
self .set_attr____ (arg , None )
137
137
# end for
138
138
139
139
# Set pairs with the key names and values from the keyword arguments
140
140
for kw in kwargs :
141
141
kw = str (kw )
142
- # print(f"_dot_dict_init **kwargs kw: {kw} arg: {kwargs[kw]}") # Debug
142
+ # print(f"_mand_init **kwargs kw: {kw} arg: {kwargs[kw]}") # Debug
143
143
144
- if not self_type .is_exc_key____ (key ):
144
+ if not self_type .is_exc_key____ (name ):
145
145
arg = kwargs [kw ]
146
146
self .set_attr____ (kw , arg )
147
147
# end for
@@ -753,14 +753,24 @@ def str____(self):
753
753
result = ".{}"
754
754
return result
755
755
756
- result = ".{"
756
+ segs = []
757
757
758
758
for key in self :
759
- result += f"{ key .__str__ ()} : { self [key ].__str__ ()} , "
759
+ val = self [key ]
760
+
761
+ if isinstance (val , DotDict ):
762
+ seg = f"{ key .__str__ ()} : { val .__str__ ()} , "
763
+ else :
764
+ seg = f"{ key .__str__ ()} : { val .__repr__ ()} , "
765
+ # end if
766
+
767
+ segs .append (seg )
768
+ # end for
760
769
761
- result = result [: - 2 ] # Remove the trailing comma and space
762
- result += "}"
770
+ contents = "" . join ( segs )
771
+ contents = contents [: - 2 ] # Remove the trailing comma and space
763
772
773
+ result = f".{{{ contents } }}"
764
774
return result
765
775
766
776
def to_dict____ (self ):
0 commit comments