Python

General

echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool

... performs json styling on the input string



python -m SimpleHTTPServer 8000

python3 -m http.server 8000 --bind 127.0.0.1

... starts a very basic web server serving files relative to the current directory



python -m py_compile script.py

... compiles script.py without running it



gettext

pygettext.py -d mydomain -p locale/no/LC_MESSAGES gettext_pod.py another.py

... processes 'gettext_pod.py' and 'another.py' and creates mydomain.pot inside locale/no/LC_MESSAGES



msgmerge -U mydomain.po mydomain.pot

... merges mydomain.pot into the existing mydomain.po



msgfmt.py -o mydomain.mo mydomain.po

... creates a binary (.mo) file out of the mydomain.po file



Sphinx

sphinx-apidoc -F -o html -H pyotp2289 -A "Simeon Simeonov" -V "1.0.0" otp2289

... generates the pyotp2289 API



Hacks

import inspect

inspect.getmro(type(obj))

... list the MRO of the given type



import traceback

traceback.print_stack()

... lists the call stack



data[:] = [elem for elem in data if elem != target]

... creates a new, distinct list and then replaces the old contents all at once

2026-04-11 13:02:19

minicms - © 2020-2026 Simeon Simeonov