Skip to main content Brad's PyNotes

Posts

2025

  1. PEP 544: Protocols - Structural Subtyping (Static Duck Typing)

    TL;DR

    PEP 544 introduces Protocol classes that enable structural subtyping (static duck typing) - type checking based on what methods an object has rather than its inheritance hierarchy, making Python’s type system more flexible and duck-typing friendly.

  2. Timeit Module: Precision Performance Measurement

    TL;DR

    The timeit module provides precise execution time measurement for small code snippets, automatically handling timing complexities and providing both programmatic and command-line interfaces for performance benchmarking.

  3. Tempfile Module: Secure Temporary File Handling

    TL;DR

    The tempfile module creates secure temporary files and directories with automatic cleanup, preventing race conditions and ensuring cross-platform compatibility for safe temporary data handling.

  4. UUID Module: Generating Universally Unique Identifiers

    TL;DR

    The uuid module generates 128-bit universally unique identifiers using multiple methods - random (uuid4), time-based (uuid1), or namespace-based (uuid3/uuid5) - perfect for unique IDs in databases and distributed systems.

  5. Decimal Module: Precise Decimal Arithmetic

    TL;DR

    The decimal module provides exact decimal arithmetic without floating-point precision errors, essential for financial calculations, scientific computing, and any application requiring precise decimal representation.

  6. Urllib Module

    TL;DR

    The urllib package provides URL handling through four submodules: request (fetch URLs), parse (manipulate URLs), error (exceptions), and robotparser (robots.txt).

    Interesting!

    Unlike many languages that require external libraries, Python includes full-featured HTTP client capabilities right in the standard library!

  7. Sys Module: System-Specific Parameters and Functions

    TL;DR

    The sys module provides access to interpreter variables like sys.argv (command-line arguments), sys.path (module search paths), sys.version, sys.exit(), and functions for interacting with the Python runtime environment.

  8. PEP 604 Union Types

    TL;DR

    PEP 604 introduced the | operator for union types, allowing int | str instead of Union[int, str] for cleaner type annotations.

    Interesting!

    The | operator for union types makes Python’s type hints look more like mathematical set notation - int | str means “integer OR string”!

  9. PEP 570 Positional Only

    TL;DR

    PEP 570 introduced the / separator to mark positional-only parameters, giving API designers control over function call semantics and preventing keyword argument usage.

  10. Multiprocessing Module

    TL;DR

    The multiprocessing module creates separate Python processes that bypass the GIL, enabling true parallel execution for CPU-intensive tasks.

    Interesting!

    Unlike threading, multiprocessing actually uses multiple CPU cores simultaneously - each process has its own Python interpreter and memory space!

  11. Zipfile Module

    TL;DR

    The zipfile module provides tools for creating, reading, and extracting ZIP archives with support for multiple compression methods and password protection.

    Interesting!

    The module supports ZIP64 extensions, allowing you to work with ZIP files larger than 4GB and containing more than 65,535 files - breaking traditional ZIP format limits!

  12. Tutorial: Whetting Your Appetite

    TL;DR

    Python excels at automation and rapid development with its simple syntax, powerful features, and “batteries included” philosophy - perfect for getting things done quickly.

  13. Tutorial: What Now? (after Python basics)

    TL;DR

    After learning Python basics, dive into the Standard Library, explore PyPI packages, join the community, and tackle real-world projects.

    Interesting!

    Python has one of the most comprehensive standard libraries of any programming language - so much functionality is available without installing anything extra!

  14. Tutorial: Stdlib Tour 2

    TL;DR

    The second stdlib tour covers professional-grade modules: precise decimal arithmetic, efficient data structures, logging, threading, and binary data handling.

    Interesting!

    The decimal module can represent exact monetary values without floating-point errors - crucial for financial applications where precision matters!

  15. String Module

    TL;DR

    The string module provides string constants, Template class for simple substitution, and advanced formatting utilities for text processing.

    Interesting!

    The string.Template class provides a safer alternative to % formatting - it prevents code injection by not allowing arbitrary expressions!

  16. Pickle Module

    TL;DR

    The pickle module serializes Python objects to bytes and deserializes them back - enabling object persistence and inter-process communication.

    Interesting!

    Pickle can serialize almost any Python object, including functions, classes, and nested objects - but never unpickle untrusted data as it can execute arbitrary code!

  17. PEP 622 Pattern Matching

    TL;DR

    PEP 622 introduced match-case statements for structural pattern matching, enabling elegant destructuring and dispatch based on data shape and values.

    Interesting!

    Pattern matching brings functional programming elegance to Python - you can destructure complex nested data in a single line and handle different cases cleanly!

  18. PEP 3107 Function Annotations

    TL;DR

    PEP 3107 introduced syntax for adding metadata to function parameters and return values, stored in __annotations__ - the foundation for modern type hints.