Skip to main content Brad's PyNotes

Posts

2025

  1. Textwrap Module: Elegant Text Formatting and Wrapping

    TL;DR

    The textwrap module provides functions for formatting text blocks with intelligent line wrapping, indentation control, and paragraph formatting - perfect for creating clean output, documentation, and user interfaces.

  2. Struct Module: Binary Data Processing and C Integration

    TL;DR

    The struct module converts between Python values and C structs represented as bytes objects, enabling binary data processing for network protocols, file formats, and hardware communication with precise control over byte layout.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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!

  9. 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.

  10. 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”!

  11. 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.

  12. 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!

  13. 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!

  14. What Now Tutorial

    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!