peep dis (verb phrase, imperative): "Check this out" or "Hey! Have a look at this."
Overview • Features • Usage • Upcoming Features
Show the outputs of methods and attributes of an object. An example for a numpy array is shown here.
- Evaluates and color codes attributes and callables
- Duplicates object to avoid state alterations
- Choose whether builtin and private attributes and methods are included
- Attempt to forge arguments from type hints (in development)
- Track object state changes (in development)
Install
pip install peepdis
Import
from peepdis import peep
Peep Imported Objects
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
peep(df)
Peep Your Own Objects
class Square:
def __init__(self, a, b, name=None):
self.a = a
self.b = b
self.name = name
def ratio(self):
return self.a / self.b
def area(self):
return self.a * self.b
sq = Rect(4, 4)
peep(sq)
Include Builtins (i.e. Magics)
Controls the inclusion of "magic" methods and attributes, which are denoted by leading and trailing double underscores -- e.g., "init". They are excluded by default.
peep(sq, builtins=True)
Include Private Attributes and Methods
Controls the inclusion of private methods and attributes, which are denoted by a single leading underscore -- e.g., "_method_name". They are excluded by default.
peep(sq, privates=True)
Print Docstrings With Output
peep(sq, docstrings=True)
Truncate Output Length
Controls maximum number of characters for each method or attribute output. No truncation will occur if None
or 0
. Set at 250 characters by default.
peep(sq, truncate_len=None)
In the Debugger
To call peep
in the debugger, it must be wrapped in a print statement. This is consistent across pdb, ipdb, PyCharm's built-in debugger, etc.
(Pdb) print(peep(sq))
I. The Mystery Object
We have a simple mystery_obj
which contains an array of San Francisco temperatures somewhere within it, but we don't know where. We could call dir
, then iteratively check each method/attribute, or we could just peep
the object.
We can quickly identify stdtemp
as the attribute we need.
Built-ins are filtered out, and outputs for the rest of the attributes and methods without positional arguments are printed. Methods are colored purple, and attributes are cyan. The outputs from methods requiring positional arguments are grayed out to allow us to skim others more quickly.
II. What's the name of that method?
We have a DataFrame
with the columns temp
and humidity
for San Francisco, which we want to convert to a narrow data model for an API we are building. There's a one-liner for this, but nothing stands out in dir
, and nothing turns up on Stack Overflow. If we peep the DataFrame, we'll quickly identify melt
as the method we need.
Argument Forging
Sometimes a method requires one simple argument to run, like an index. By forging simple arguments like these, we can see example outputs from methods that we wouldn't otherwise be able to see. The sample code which this feature will be based on can be found in the accompanying blog post at ____.
Tracking State Changes
Often, a method call changes the state of the object. Tracking state changes would allow us to see understand what these types of methods do. The sample code which this feature will be based on can be found in the accompanying blog post at ____.
Customizable Preferences and Color Scheme