'
-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()
+
|