Tag: Python
-
Python List Comprehension
I’ve been spending time with Python recently and am beginning to really like some of the language’s features. List comprehension creates a list by evaluating an expression on each item in each list, from left to right. It combines an expression and a loop: Apply a condition : It’s useful for combining lists: Pimoroni’s Rainbow Hat…
-
Using Threading rather than Thread
In an earlier post, I used Threads but the thread module in Python when I should be using threading. The documentation for threading says it builds upon the thread module (renamed _thread): This module provides low-level primitives for working with multiple threads (also called light-weight processes or tasks) — multiple threads of control sharing their global data…
-
Python’s with statement
Managing resources usually involves three steps – allocating, using, and releasing. You’re familiar with the try… finally pattern but Python also provides context managers.