Just notes on various things

Gogs cc43b6c397 Added a second example on print formatting. пре 7 година
examples cc43b6c397 Added a second example on print formatting. пре 7 година
.gitignore 1ca81aa725 Initial commit пре 7 година
LICENSE 1ca81aa725 Initial commit пре 7 година
README.md 0f2468580e First example пре 7 година

README.md

python_notes

Just notes on various things

docstrings

Use 'em.

ArgParse

Interesting Tidbits

Redirect stdout to a file. The with isolates context and prevents certain race conditions, handling errors appropriately.

with open('help.txt', 'w') as f:
    with redirect_stdout(f):
        help(pow)

Caching

If you have a function that always returns the same result for a given input, you can cache the result by prefacing with @lru_cache. e.g.

from functools import lru_cache

@lru_cache(maxsize=32)
def fib(n):
    if n < 2:
        return n
    return fib(n-1) + fib(n-2)