Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ TOML Kit provides an intuitive API to modify TOML documents::
>>> doc.pop("table2")
# del doc["table2] is also possible

Boolean comments
~~~~~~~~~~~~~~~~

Dictionary access returns a Python ``bool`` for boolean values, so comparisons
such as ``doc["enabled"] is True`` work. To access the underlying TOML item and
its formatting information (``trivia``), use ``item(key)`` on the document or
table. Read the comment with ``trivia.comment`` and update it with ``comment()``::

>>> doc = parse("enabled = true # Root\n[database]\nenabled = false # Database\n")
>>> doc["enabled"] is True
True
>>> doc["database"]["enabled"] is False
True
>>> doc.item("enabled").trivia.comment
'# Root'
>>> enabled = doc["database"].item("enabled")
>>> enabled.trivia.comment
'# Database'
>>> _ = enabled.comment("Updated database comment")
>>> print(dumps(doc), end="")
enabled = true # Root
[database]
enabled = false # Updated database comment

Writing
-------

Expand Down