Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python TOML code

Practice parsing TOML strings and files and handling parsed configuration data.

Intermediate ~8 min read

Challenge 1

Parse the TOML string into Python data.

python Your answer
import tomllib

data = 'name = \"Foxipa\"'
config = 
print(config["name"])

Press Ctrl⌘Enter to check your answer

Challenge 2

Parse the open binary TOML file.

python Your answer
import tomllib
from io import BytesIO

file = BytesIO(b'name = \"Foxipa\"\n')
config = 
print(config)

Press Ctrl⌘Enter to check your answer

Challenge 3

Read the host value from the parsed server table.

python Your answer
config = {"server": {"host": "localhost"}}
host = 
print(host)

Press Ctrl⌘Enter to check your answer

Challenge 4

Parse TOML floats as Decimal values.

python Your answer
from decimal import Decimal
import tomllib

config = tomllib.loads("price = 19.95", parse_float=)
print(config["price"])

Press Ctrl⌘Enter to check your answer