Created
July 27, 2016 01:00
-
-
Save mzipay/fe089c101038d37e92607adc1989ad3c to your computer and use it in GitHub Desktop.
Some BaSH functions I use for finding/viewing Python standard library modules easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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