Find and inspect python functions
Project description
pyinspect
If, like me, when coding often you know which function you need but can't quite remember
its name, then I have good news!. pyinspect
is here to help you out.
pyinspect
allows you to search for functions and class methods based on their name and
prints out a handy table with all the functions that met your search criteria.
Finding functions
The easiest way to grasp how pyinspect
can help is with an example.
Imagine that you just can't remember which
matplotlib.pyplot
method you need to create a figure with subplots...
this is how you use pyinspect
to find it:
# import the module whose functions you're looking for
import matplotlib.pyplot as plt
# import pyinspect
import pyinspect
# Find the functions you're looking for
funcs = pyinspect.find(plt, name='subplot')
This results in:
pyinspect.find
can also be used to find class attributes. For example,
say that you're looking for a method with export
in the name in rich.console.Console
:
# import the class you're using
from rich.console import Console
# import pyinspect
import pyinspect
# find class methods
methods = pyinspect.find(Console, 'export')
Which gives:
PRO TIP: if you don't pass a search string (e.g. pyinspect.find(Console)
), pyinspect.find
will print all functions and methods.
Inspecting functions
Okay, you've found the function you need, that's great. But how does it work?
What if, in addition to the exact name you've forgotten which arguments it takes, or how it
works exactly. Well, pyinspect
can help you there as well!
You can use pyinspect.print_function
to print the source code of any function or attribute:
# import the class you're using
from rich.console import Console
# import pyinspect
import pyinspect
# Print a function's source code
pyinspect.print_function(Console.export_text)
which yields:
Tracebacks
Finally, pyinspect
builds upon rich
's awesome traceback
functionality to
print nicely formatted tracebacks and show the local variables
when the exception came up.
E.g.:
# import pyinspect installs the traceback handler
import pyinspect
# make some buggy code
import numpy as np
a = np.ones(5)
b = np.zeros(4)
a / b
and this is the traceback:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyinspect-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9da735500a975fc397736382b84d18dc97c13a6f2d83b773c54546f796b20b0a |
|
MD5 | f4c7cdbbbcba99ded30401623b481dc6 |
|
BLAKE2b-256 | d23b4071aca78904dcd61e463e57af0a7f257fb2c0f84c52c44f81e933508a7b |