The help()
function gets added to the builtin namespace by the site
module, which you can customize by creating a sitecustomize.py
module somewhere on your path (apparently it's usually kept in site-packages).
Then in the sitecustomize.py
file you add whatever customizations you want.
You could handle this a couple of ways:
If you want to change the (apparent) behavior of the help()
function itself, wrap the help function in a decorator, something like:
def help_wrapper(func):
def inner(*args):
results = func(*args)
return your_cleanup_function_here(results)
help = help_wrapper(help)
I would personally prefer a slightly different solution, because there's no telling what your cleanup function will do to help output that isn't written in RestructuredText.
So I would just create a wrapper function:
def my_help(*args):
return your_cleanup_function_here(help(*args))
This way you still have access to the original help()
function if you need it.
CAVEAT: be cautious when doing things in sitecustomize.py, as whatever you do here will likely affect your entire interpreter session (and every interpreter session), which can sometimes lead to unintended consequences.
help()
. It's not so difficult as may seem; just some inspect code and launching the pager. Really wouldn't be hard. – Bean