Skip to content

Latest commit

 

History

History
66 lines (46 loc) · 2.49 KB

python.md

File metadata and controls

66 lines (46 loc) · 2.49 KB

Python

Language

Decorator

Reference First joined version Python Enhancement Proposals
Function decorator 2.4.1 PEP 318
Class decorator 2.6 PEP 3129

Utility

pip

Upgrade all outdated pip packages (homepage)

pip3 install pip-upgrade-outdated
pip_upgrade_outdated -3

Sync installed pip packages (doc)

# optional, in case "pip3" is still linked to the old version
brew unlink [email protected] && brew link [email protected]
pip3 freeze [--path /usr/local/lib/python3.8/site-packages] > requirements.txt
pip3 install -r requirements.txt

pyenv

  • Install pyenv itself: brew info pyenv
  • Set PATH: PATH=$(pyenv root)/shims:$PATH (ref)
  • Install another version of Python: [email protected] pyenv install 3.4.4 (ref)
  • Locally set Python version: cd <path> && pyenv local 3.4.4

Standard Libraries

subprocess

import subprocess

# run shell command `ls -l` and capture the output
result = subprocess.run(['ls', '-l'], capture_output=True)
result.stdout.decode('utf-8')

Third-party Packages

  • colorama - Print colored terminal text.