import secrets, string, textwrap
from string import Template
secrets.token_hex(16) # 32 hex znaků
secrets.token_urlsafe(32) # do URL
secrets.choice(abeceda) # bezpečný výběr
secrets.randbelow(100) # 0 až 99
secrets.compare_digest(a, b) # porovnání tokenů
string.ascii_letters # a-zA-Z, bez diakritiky
string.digits # 0-9
string.punctuation # interpunkce
Template("Ahoj $jmeno").substitute(jmeno="Eva")
Template("$a").safe_substitute() # chybějící nechá
textwrap.wrap(t, width=40) # seznam řádků
textwrap.fill(t, width=40) # jeden text
textwrap.shorten(t, width=40, placeholder="…")
textwrap.dedent(t) # odebere odsazení
textwrap.indent(t, "> ") # přidá předponuTahák · Python · Užitečné knihovny
secrets, string a textwrap
Bezpečné tokeny a hesla, šablony textu bez děr a zalamování řádků včetně české typografie. Tři malé knihovny pro každodenní práci s textem.