Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some BaSH functions I use for finding/viewing Python standard library modules easily
# show the location of a Python module's .py
# usage: pyfn module.name [pyversion]
# example: "pyfn hashlib", "pyfn hashlib 3.5", "pyfn hashlib 2"
function pyfn {
test -z "${1}" && return 1
fn=$(python${2} -c "import ${1},sys;sys.stdout.write(getattr(${1},'__file__').rsplit('.',1)[0]+'.py')")
test -f "${fn}" && echo "${fn}"
}
# open a Python module's .py in vi (read-only)
# usage: vipy module.name [pyversion]
# example: "vipy hashlib", "vipy hashlib 3.5", "vipy hashlib 2"
function vipy {
fn=$(pyfn ${1} ${2})
test -f "${fn}" && vi -R "${fn}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment