in mujoco_worldgen/parser/normalize.py [0:0]
def stringify(xml_dict):
'''
De-normalize xml dictionary (or list), converting all pythonic values (arrays, bools)
into strings that will be used in the final XML.
This is the opposite of normalize().
'''
if isinstance(xml_dict, OrderedDict):
enumeration = list(xml_dict.items())
elif isinstance(xml_dict, list):
enumeration = enumerate(xml_dict)
for key, value in enumeration:
# Handle a list of nodes to stringify
if isinstance(value, list):
if len(value) == 0:
del xml_dict[key]
else:
if sum([isinstance(v, (int, float, np.float32, np.int)) for v in value]) == len(value):
xml_dict[key] = vec2str(value)
else:
stringify(value)
elif isinstance(value, OrderedDict):
stringify(value)
elif isinstance(value, (np.ndarray, tuple)):
xml_dict[key] = vec2str(value)
elif isinstance(value, float):
xml_dict[key] = num2str(value) # format with fixed decimal places
elif isinstance(value, bool): # MUST COME BEFORE int() CHECK
xml_dict[key] = str(value).lower() # True -> 'true', etc.
elif isinstance(value, int): # isinstance(True, int) -> True. SAD!
xml_dict[key] = str(value) # Format without decimal places
elif isinstance(value, str):
pass # Value is already fine
elif value is None:
pass
else:
raise ValueError(
'Bad type for key {}: {}'.format(key, type(value)))