|
def debug_element(obj): |
|
"""Get all attributes and their string representations from an object using dir().""" |
|
import copy |
|
try: |
|
|
|
obj_copy = copy.deepcopy(obj) |
|
except: |
|
try: |
|
|
|
obj_copy = copy.copy(obj) |
|
except: |
|
|
|
obj_copy = obj |
|
|
|
attributes = dir(obj_copy) |
|
results = [] |
|
|
|
for attr in attributes: |
|
try: |
|
|
|
value = getattr(obj_copy, attr) |
|
|
|
|
|
if callable(value): |
|
try: |
|
|
|
result = value() |
|
str_value = f"<callable result: {str(result)}>" |
|
except Exception as call_error: |
|
|
|
str_value = f"<callable: {type(value).__name__} - error when called: {str(call_error)}>" |
|
else: |
|
str_value = str(value) |
|
|
|
results.append(f"{attr}: {str_value}") |
|
except Exception as e: |
|
results.append(f"{attr}: <error accessing: {str(e)}>") |
|
|
|
return results |