@@ -64,7 +64,7 @@ def from_dict____(cls, dict_):
6464 Returns:
6565 result: the resulting DotDict
6666 """
67- # print(f"fromdict____ dic : {dic }") # Debug
67+ # print(f"from_dict____ dict_ : {dict_ }") # Debug
6868 result = DotDict ()
6969
7070 for key in dict_ :
@@ -115,33 +115,33 @@ def _mand_init(self, *args, **kwargs):
115115
116116 # Set the inherited keys from the custom class level
117117 if self_type is not DotDict and issubclass (self_type , DotDict ):
118- class_dict = self_type . __dict__
118+ class_dir = dir ( self_type )
119119
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
123123
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 )
127127 # end for
128128 # end if
129129
130130 # Set keys with the key names from the variable arguments
131131 for arg in args :
132132 arg = str (arg )
133- # print(f"_dot_dict_init *args arg: {arg}") # Debug
133+ # print(f"_mand_init *args arg: {arg}") # Debug
134134
135- if not self_type .is_exc_key____ (key ):
135+ if not self_type .is_exc_key____ (name ):
136136 self .set_attr____ (arg , None )
137137 # end for
138138
139139 # Set pairs with the key names and values from the keyword arguments
140140 for kw in kwargs :
141141 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
143143
144- if not self_type .is_exc_key____ (key ):
144+ if not self_type .is_exc_key____ (name ):
145145 arg = kwargs [kw ]
146146 self .set_attr____ (kw , arg )
147147 # end for
@@ -753,14 +753,24 @@ def str____(self):
753753 result = ".{}"
754754 return result
755755
756- result = ".{"
756+ segs = []
757757
758758 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
760769
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
763772
773+ result = f".{{{ contents } }}"
764774 return result
765775
766776 def to_dict____ (self ):
0 commit comments