See the example usage inside configparser.py
. Output when running the configparser.py
file:
# Comments may appear before the first section
[Simple Values]
key = value
spaces in keys = allowed
spaces in values = allowed as well
spaces around the delimiter = obviously
you can also use = to delimit keys from values
# We will update some values in this section
[All Values Are Strings]
values like this = 2000000
or this = 2
# The comments will remain
are they treated as numbers? = no
# We can even use duplicate comments
# We can even use duplicate comments
integers, floats and booleans are held as = strings
# cOmMeNt cAsInG Is pReSeRvEd
can use the api to get converted values directly = true
// We can even use the // prefix to write comments
[Multiline Values]
# We can even use duplicate comments
chorus = I'm a lumberjack, and I'm okay
I sleep all night and I work all day
[No Values]
key_without_value
empty string value here =
[You can use comments]
# like this
; or this
# 1 empty line above and 2 below, also preserved
# By default only in an empty line.
# Inline comments can be harmful because they prevent users
# from using the delimiting characters as parts of values.
# That being said, this can be customized.
[Sections Can NOT Be Indented]
can_values_be_as_well = False
multiline_values = #!/usr/bin/env bash
set -euo pipefail
# You can even write a little multiline bash script
echo 'This script snippet is not mangled!'
echo "added some $RANDOM stuff from python"
# Did I mention we can NOT indent comments, either?
# Indenting is reserved to handle multiline values
we can add keys = with some value