Skip to main content Brad's PyNotes

Posts

2025

  1. Glob Module: Unix-Style Pathname Pattern Matching

    TL;DR

    The glob module finds all pathnames matching a Unix shell-style pattern using wildcards like * (any characters), ? (single character), and [seq] (character ranges), making file discovery and batch operations simple.

  2. Tutorial: Venv

    TL;DR

    Virtual environments create isolated Python installations to prevent package conflicts between projects using python -m venv.

    Interesting!

    Virtual environments solve the “dependency hell” problem - you can have different versions of the same library for different projects without conflicts!

  3. Threading Module

    TL;DR

    The threading module enables concurrent execution through threads with synchronization primitives like Lock, Event, and Semaphore for safe resource sharing.

    Interesting!

    Python’s Global Interpreter Lock (GIL) means only one thread executes Python code at once - threading helps with I/O-bound tasks, not CPU-bound ones!

  4. Sqlite3 Module

    TL;DR

    The sqlite3 module provides a lightweight, disk-based database interface that supports SQL queries without requiring a separate server process.

    Interesting!

    SQLite is the most widely deployed database engine in the world - it’s built into every smartphone, browser, and operating system!

  5. PEP 585 Generics

    TL;DR

    PEP 585 made built-in collections generic, allowing list[int] instead of List[int] - eliminating duplicate type hierarchies in the typing module.

    Interesting!

    Before PEP 585, Python had two separate type systems - one for runtime and one for type hints. Now built-in collections work for both!

  6. Heapq Module: Efficient Priority Queue Operations

    TL;DR

    The heapq module provides heap queue (priority queue) operations using a binary heap implemented as a list, where heappush() and heappop() maintain the heap invariant with O(log n) complexity.

  7. Tutorial: Stdlib Tour

    TL;DR

    Python’s standard library provides essential modules for OS operations, file handling, math, networking, dates, and performance measurement - “batteries included”!

    Interesting!

    Python’s standard library is so comprehensive that many tasks don’t require external dependencies - from web requests to compression, it’s all built-in!

  8. Tutorial: An informal intro to Python

    TL;DR

    Python’s interactive interpreter lets you experiment immediately with numbers, strings, and lists using intuitive syntax and meaningful indentation.

    Interesting!

    Python uses indentation instead of braces to define code blocks - making the visual structure of your code match its logical structure!

  9. Statistics Module

    TL;DR

    The statistics module provides mathematical statistics functions for calculating averages, spread measures, and correlations without external dependencies.

    Interesting!

    Unlike floating-point calculations, the statistics module can work with Decimal and Fraction types for exact mathematical precision in statistical calculations!

  10. PEP 492 Async Await

    TL;DR

    PEP 492 introduced async def and await keywords, creating native coroutines that make asynchronous programming cleaner and more intuitive than generator-based approaches.

  11. PEP 380 Yield From

    TL;DR

    PEP 380 introduced yield from syntax for delegating to subgenerators, simplifying generator composition and enabling generators to return values.

    Interesting!

    yield from was the foundation that made async/await possible - it established the delegation pattern that coroutines needed!

  12. CSV Module: Easy CSV File Reading and Writing

    TL;DR

    The csv module provides csv.reader(), csv.writer(), csv.DictReader(), and csv.DictWriter() for robust CSV file processing with automatic dialect detection and proper handling of quotes, delimiters, and line endings.

  13. Tutorial: Input Output

    TL;DR

    Python provides multiple string formatting methods (f-strings, .format(), manual), file operations with context managers, and JSON serialization for data exchange.

    Interesting!

    F-strings can execute any Python expression inside the braces - you can even call functions and perform calculations right inside the string!

  14. PEP 526: Variable Annotations - Type Hints for Variables

    TL;DR

    PEP 526 introduced variable annotations in Python 3.6, allowing type hints for variables using the syntax variable: type = value, extending PEP 484’s function annotations to all variables for better code documentation and static analysis.