Last active
February 6, 2018 05:30
-
-
Save DexterPOSH/e17d1308bc9106a0bfd17e537dcaed7f to your computer and use it in GitHub Desktop.
Basic & crude GetMember function, it helps me in exploring objects in Python REPL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inspect | |
def GetMember(object, width=100): | |
print("TypeName: {}\n".format(repr(object))) | |
print("{0:<40} {1:<60} {2:<100}".format('Name', 'MemberType', 'Signature')) | |
print("{0:<40} {1:<60} {2:<100}".format('----', '----------', '---------')) | |
members = inspect.getmembers(object) | |
for member in members: | |
name = str(member[0]) | |
membertype = type(member[1]) | |
if hasattr(member[-1], '__name__') and callable(member[-1]): | |
try: | |
signature = str(inspect.Signature.from_callable(member[-1])) | |
except: | |
signature = 'None' | |
else: | |
signature = 'None' | |
print("{0:<40} {1:<60} {2:<100}".format(name[:40], str(membertype)[:60], signature[:width])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment