PythiloLesson 1 of 8 · progress kept in this browser

Read real TOML configuration

TOML is a configuration format with typed values, tables and arrays. Python's tomllib reads TOML text into ordinary Python objects. It is a reader, so writing TOML is a separate concern; keep that distinction clear when designing a configuration editor.

Use loads for text and load for a binary file object. A table becomes a nested dictionary, while a port written as a TOML integer becomes an int. Supply defaults at the layer that owns them, and allow malformed syntax to produce an explicit parsing error instead of silently treating a broken file as empty configuration.

import tomllib
text = """
[server]
host = "localhost"
port = 8000
"""
settings = tomllib.loads(text)
print(settings["server"]["port"])
Your task

Implement server_config(text): parse TOML and return (host,port) from the server table. Default missing host to "localhost", missing port to 8000, and a missing server table to both defaults. Malformed TOML must raise.