Skip to content

Instantly share code, notes, and snippets.

@s-hiiragi
Created September 19, 2022 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-hiiragi/91cd04ff06e074fb63d558c31c85b0cf to your computer and use it in GitHub Desktop.
Save s-hiiragi/91cd04ff06e074fb63d558c31c85b0cf to your computer and use it in GitHub Desktop.
オブジェクトのメソッドとプロパティを継承元ごとに表示
def print_attrs(value):
from functools import reduce
mro = type(value).mro()
attrsets = [set(dir(x)) for x in mro] + [set()]
ownattrsets = [x - attrsets[i+1] for i,x in enumerate(attrsets) if i < len(mro)]
for type_, ownattrset in zip(mro, ownattrsets):
print(type_.__name__)
print(' ', list(ownattrset))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment