Skip to content

Python - Tips

Useful

Execute http server:

# Python 2.x
python -m SimpleHTTPServer {port}

# Python 3.x
python -m http.server {port}

Format JSON:

cat data.json | python -m json.tool

Download file from http (like curl):

python -c 'import urllib;urllib.urlretrieve("url", "dest")'
# Ex:
#   python -c 'import urllib;urllib.urlretrieve("https://m2ki.com/file.txt", "/data/file.txt")'
Back to top