From 1e337965cbccde71121ea11923c69b5196f55717 Mon Sep 17 00:00:00 2001 From: David Greaves Date: Mon, 5 Jul 2021 19:37:43 +0100 Subject: [PATCH] Tutorial: Show the dict from toml.loads() It is not clear how the toml structure, in particular the "[servers.alpha]" idiom, is mapped to a python dict. This makes the tutorial much more complete --- README.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.rst b/README.rst index b65ae72..dd33a35 100644 --- a/README.rst +++ b/README.rst @@ -85,6 +85,24 @@ returns a dictionary containing the parsed data. ... """ >>> parsed_toml = toml.loads(toml_string) +Results in this dict structure: + +.. code:: pycon + + >>> import pprint + >>> pprint.pprint(parsed_toml) + {'clients': {'data': [['gamma', 'delta'], [1, 2]], 'hosts': ['alpha', 'omega']}, + 'database': {'connection_max': 5000, + 'enabled': True, + 'ports': [8001, 8001, 8002], + 'server': '192.168.1.1'}, + 'owner': {'dob': datetime.datetime(1979, 5, 27, 7, 32, tzinfo=), + 'name': 'Tom Preston-Werner'}, + 'servers': {'alpha': {'dc': 'eqdc10', 'ip': '10.0.0.1'}, + 'beta': {'dc': 'eqdc10', 'ip': '10.0.0.2'}}, + 'title': 'TOML Example'} + + *toml.dumps* takes a dictionary and returns a string containing the corresponding TOML-formatted data.