configrw
stable
  • 1. Installation
  • 2. Quick start
  • 3. Load config
  • 4. Management of sections
  • 5. Management of items of section
  • 6. Print data
  • 7. Write data to a file
configrw
  • Docs »
  • 6. Print data
  • Edit on GitHub

6. Print dataΒΆ

print(config)

Output:

[
    {'key': 'global_parameter', 'sep': ' = ', 'value': 1}
],
{'section1':
    [
        {'key': '    option0', 'sep': ' = ', 'value': 0},
        {'key': '    option_without_value', 'sep': None, 'value': None},
        '    # This is comment for option1',
        {'key': '    option1', 'sep': ' = ', 'value': 100}
    ]
}
print(config['section1'])

Output:

[
    {'key': '    option0', 'sep': ' = ', 'value': 0},
    {'key': '    option_without_value', 'sep': None, 'value': None},
    '    # This is comment for option1',
    {'key': '    option1', 'sep': ' = ', 'value': 100}
]

Also you can use method to_text() for all config or for a section:

for line in config.to_text():
    print(line)

Output as text format:

global_parameter = 1
[section1] # this is comment
    option0 = 0
    option_without_value
    # This is comment for option1
    option1 = 100
Next Previous

© Copyright 2019, microcoder Revision 7368ec28.

Built with Sphinx using a theme provided by Read the Docs.