Data formats: XML, INI, TOML and pickle · 12 / 15 Exercise Medium

Read a TOML file

Objective

TOML is the modern configuration format of Python (pyproject.toml uses it). With tomllib (Python 3.11+) a file becomes dictionaries and lists with real types: strings, integers, booleans and lists.

Instructions

  • The file config.toml exists with the key title, a table [server] with the list ports and, optionally, a list of tables [[users]] with name and role.
  • Show the title, Ports: sum with the sum of the ports and one line name (role) for each user. Remember to open the file in binary mode.
Output
Demo
Ports: 8603
ana (admin)
luis (guest)

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise