restructuredText, docstring and python interactive shell -
i using restructuredtext document code, nice offline html pages means of epydoc.
results brilliant. drawback when use python interactive shell, help() function not parse rest metadata in documentation strings, , instead displays whole thing is.
is there way have help() minimal parsing of docstrings?
i don't expect rendering of italic fonts or hyperlinks, @ least minimal cleanup increase readbility.
the help() function gets added builtin namespace site module, can customize creating sitecustomize.py module somewhere on path (apparently it's kept in site-packages).
then in sitecustomize.py file add whatever customizations want.
you handle couple of ways:
if want change (apparent) behavior of help() function itself, wrap function in decorator, like:
def help_wrapper(func): def inner(*args): results = func(*args) return your_cleanup_function_here(results) = help_wrapper(help) i prefer different solution, because there's no telling cleanup function output isn't written in restructuredtext.
so create wrapper function:
def my_help(*args): return your_cleanup_function_here(help(*args)) this way still have access original help() function if need it.
caveat: cautious when doing things in sitecustomize.py, whatever here affect entire interpreter session (and every interpreter session), can lead unintended consequences.
Comments
Post a Comment