Skip to content

Instantly share code, notes, and snippets.

@AlbericC
Created October 31, 2015 14:43
Show Gist options
  • Save AlbericC/64eb61d8a760e079f576 to your computer and use it in GitHub Desktop.
Save AlbericC/64eb61d8a760e079f576 to your computer and use it in GitHub Desktop.
def verbal(some_class):
"""intended as a class decorator allowing to list all attributes and where
they come from"""
def tell(inst):
print(
"{:>16}: {}\n"
.format("instance",
", ".join(a
for a in vars(inst)
if not a.startswith("__")
)
)
+
"".join(["{:>16}: {}\n"
.format(cls.__name__,
", ".join(
sorted([a
for a in vars(cls)
if not a.startswith("__")]
)
)
)
for cls in type(inst).__mro__]
)
+
"{:>16}: {}\n".format(type(type(inst)).__name__,
", ".join(a
for a in vars(type(type(inst)))
if not a.startswith("__")
)
)
)
some_class.tell = tell
return some_class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment