Skip to content

Instantly share code, notes, and snippets.

@taleinat
Last active October 7, 2022 08:38
Show Gist options
  • Save taleinat/78d3d6358e9f64cbf311d8219414facd to your computer and use it in GitHub Desktop.
Save taleinat/78d3d6358e9f64cbf311d8219414facd to your computer and use it in GitHub Desktop.
Useful Python Shell Commands

Useful Python Shell Commands.

I find these especially useful in containers with Python but not much else.

File Download

python -c 'from urllib.request import urlretrieve; urlretrieve("https://bootstrap.pypa.io/get-pip.py", filename="target/path/get-pip.py")'

Format JSON

Multi-line with indentation:

echo '[{"a":"b", "c":"d"}]' | python -m json.tool [--compact]

Unzip

python -m zipfile -e path/to/file.zip target/path

HTTP Server

python -m http.server [--directory PATH] [--bind address] [PORT]
  • The default port is 8000.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment