From 5385052095487f40137d5a9fe281fe35b14367ad Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Sat, 23 Oct 2021 20:25:03 +0200 Subject: [PATCH] added Size column (show obj.shape, len(obj) or nothing) --- inspector.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/inspector.py b/inspector.py index 6dec32f..783f61b 100644 --- a/inspector.py +++ b/inspector.py @@ -6,10 +6,10 @@ import ipywidgets -HEADER = '
NameTypeValue
' +HEADER = '' SEP = '
' -LINE = '{0}{1}{2}' +LINE = '{0}{1}{2}{3}' IGNORE = ["In", "Out", "exit", "quit", "get_ipython"] @@ -30,7 +30,7 @@ class Singleton(type): inst = super().__call__(*args, **kwargs) # creates the instance (calls __new__ and __init__ methods) cls.__instance__ = weakref.ref(inst) return inst - + class VariableInspector(object, metaclass=Singleton): @@ -79,7 +79,7 @@ class VariableInspector(object, metaclass=Singleton): def format_line(k, v): - return LINE.format(k, typename(v), v) + return LINE.format(k, typename(v), size(v), v) def sorted_naturally(iterable, reverse=False): natural = lambda item: [int(c) if c.isdigit() else c.casefold() for c in RE_DIGITS.split(str(item))] @@ -91,8 +91,18 @@ def is_good_entry(k, v): def typename(obj): return type(obj).__name__ +def size(obj): + try: + return obj.shape + except AttributeError: + try: + return len(obj) + except TypeError: + return "" + inspector = VariableInspector() +