Chapter 9

Reading Objects and Records

Read the attributes, method calls, signatures, small classes, type hints, and records that appear throughout numerical Python.

You have already used dot notation with strings, paths, and collection tools. We will now read that notation consistently: start with the object, select an attribute or method, and call the method only when parentheses are present. A documented signature then tells us which arguments a call accepts and what it returns.

A small class makes instance fields, methods, and `self` visible without turning this chapter into a course on object-oriented design. Type hints describe the values expected at a boundary. A dataclass uses the same notation to declare a plain record and generate its routine setup.

The chapter ends with one measurement workflow. The readings remain input data, thresholds and unit become configuration, and the analysis returns a named result. Running the same data with two configurations makes the effect of those choices easy to inspect.

After this chapter

  • Distinguish attribute selection, method calls, and dictionary-key lookup.
  • Map required parameters, optional defaults, positional arguments, and keyword arguments from a documented signature to one call.
  • Trace a small class, its constructor call, self, separate instances, and an alias.
  • Interpret collection and optional type hints without mistaking them for runtime enforcement.
  • Use a frozen dataclass as a plain record and state the limits of generated behavior.
  • Pass validated configuration explicitly and return named evidence for two comparable runs.

Lessons

  1. 01
    Read Attributes and Method Calls

    Read attributes and method calls, then use type and AttributeError as evidence when access fails.

    3 exercises
  2. 02
    Read a Library Signature

    Read a documented signature, account for defaults, and inspect the returned value and type.

    3 exercises
  3. 03
    Read a Small Class

    Read a small class and trace how constructor arguments and method calls use one particular instance.

    3 exercises
  4. 04
    Read Type Hints at Boundaries

    Read a typed function boundary and keep its declared expectations separate from runtime behavior.

    3 exercises
  5. 05
    Use a Dataclass as a Plain Record

    Construct and inspect a frozen dataclass record without assuming deep immutability or automatic validation.

    3 exercises
  6. 06
    Pass Configuration and Return Results

    Validate an explicit configuration, analyze fixed input, and compare two returned results without hidden global state.

    3 exercises

Review and practice

  1. Review

    Review object access, signatures, instances, hints, records, and the roles of configuration, input, and result.

  2. Exercises

    Practice object access and record boundaries in ten cumulative exercises.

Optional and reference

  1. Check Type Hints Locally

    Optional local setup and one focused static type-checking example.

Chapter progress