2022-03-01 08:01:56 +01:00
|
|
|
def object_to_str(obj, keys):
|
|
|
|
"""Return a string representation of an object."""
|
|
|
|
s = ""
|
|
|
|
for key in keys:
|
|
|
|
value = eval("obj." + key)
|
|
|
|
key = key.replace("()", "")
|
2022-04-26 13:12:43 +02:00
|
|
|
if isinstance(value, str):
|
2022-03-01 08:01:56 +01:00
|
|
|
s += f"{key} = {value}\n"
|
2022-04-26 13:12:43 +02:00
|
|
|
elif isinstance(value, list):
|
2022-03-01 08:01:56 +01:00
|
|
|
for idx, vv in enumerate(value):
|
|
|
|
if not vv:
|
|
|
|
s += f"{key}[{idx}] = \n"
|
|
|
|
continue
|
|
|
|
s += f"{key}[{idx}] = {vv}\n"
|
2022-04-26 13:12:43 +02:00
|
|
|
elif isinstance(value, dict):
|
2022-03-01 08:01:56 +01:00
|
|
|
for vv_key in value.keys():
|
|
|
|
vv_value = value[vv_key]
|
|
|
|
if not vv_value:
|
|
|
|
s += f"{key}.{vv_key} = \n"
|
|
|
|
continue
|
|
|
|
s += f"{key}.{vv_key} = {vv_value}\n"
|
|
|
|
else:
|
|
|
|
s += f"{key} = {str(value)}\n"
|
|
|
|
return s
|