added Size column (show obj.shape, len(obj) or nothing)
This commit is contained in:
18
inspector.py
18
inspector.py
@ -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()
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user