added Size column (show obj.shape, len(obj) or nothing)

This commit is contained in:
2021-10-23 20:25:03 +02:00
parent 25462f27d3
commit 5385052095

View File

@ -6,10 +6,10 @@ import ipywidgets
HEADER = '<div class="rendered_html jp-RenderedHTMLCommon"><table><thead><tr><th>Name</th><th>Type</th><th>Value</th></tr></thead><tr><td>'
HEADER = '<div class="rendered_html jp-RenderedHTMLCommon"><table><thead><tr><th>Name</th><th>Type</th><th>Size</th><th>Value</th></tr></thead><tr><td>'
FOOTER = '</td></tr></table></div>'
SEP = '</td></tr><tr><td>'
LINE = '{0}</td><td>{1}</td><td>{2}'
LINE = '{0}</td><td>{1}</td><td>{2}</td><td>{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()