3 ms·
For Python programmers, I have a bash/zsh function called `pycd` that takes any Python package/module name as an argument, and changes your current working dire
by pixelmonkey 8y ago
For Python programmers, I have a bash/zsh function called `pycd` that takes any Python package/module name as an argument, and changes your current working directory to be the library or site-packages location of that library, according to the current python interpreter in your $PATH. Here it is:
pycd () {
pushd `python -c "import os.path, $1; print(os.path.dirname($1.__file__))"`;
}
Example usage, with abbreviated $PWD shown after "»" and shell commands entered after "$" in this example session:
» (~/repos/web)
$ pycd flask
» (~/./v/3/e/w/l/p/s/flask)
$ pwd
~/.pyenv/versions/web+site/lib/python3.6/site-packages/flask
» (~/./v/3/e/w/l/p/s/flask)
$ head app.py
# -*- coding: utf-8 -*-
"""
flask.app
~~~~~~~~~
This module implements the central WSGI application object.
:copyright: © 2010 by the Pallets team.
:license: BSD, see LICENSE for more details.
"""
» (~/./v/3/e/w/l/p/s/flask)
$ popd
~/repos/web ~
» (~/repos/web)
$
So, usually lets you explore the source code, at the command-line, for any Python libraries you have installed.