Skip to content

Instantly share code, notes, and snippets.

@AndreLester
Created September 28, 2024 15:56
Show Gist options
  • Save AndreLester/bbb59565b56fca80018f3a3879f80e4a to your computer and use it in GitHub Desktop.
Save AndreLester/bbb59565b56fca80018f3a3879f80e4a to your computer and use it in GitHub Desktop.
Returns all properties and methods of the specified object in a tabular form.
import math
from tabulate import tabulate
def methods(itarget, columns=4, private=False, search=None):
dtable = list()
itarget = dir(itarget)
methods = list()
for i, item in enumerate(itarget):
if item[0] == '_' and private != True:
continue
if search is not None and search.lower() not in item.lower():
continue
methods.append(item)
rows_count = math.ceil(len(methods)/columns)
for i in range(rows_count):
dtable.append(list())
while len(methods) > 0:
for i in range(rows_count):
if len(methods) == 0:
break
else:
item = methods.pop(0)
dtable[i].append(item)
print(tabulate(dtable, tablefmt='rounded_outline'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment