1. Thread Locals in Python: Mostly easy

    Thread locals are an interesting idea: a way to give each thread its own storage, useful for global state that you don't want to share between threads.

    The obvious caveat is that threadlocals are still effectively global (for the current thread), and like all global state, should be treated with …

  2. Python One-Liners: Generator expressions

    Here's a typical loop that checks for some condition and breaks the first time it passes:

        def list_contains_urls(maybe_urls):
            for url in maybe_urls:
                 if url.startswith('http'):
                      return True
            return False
    

    Can we do that more concisely? Sure.

        def list_contains_urls(maybe_urls):
             return any(u for u in maybe_urls if u …
    Tagged as : programming python

Page 2 / 4