maci.inibuildauto

auto builds a configparser object from dict

Auto builds a ConfigParser object from a dictionary with a correct section and key/value structure.

maci.inibuildauto -> ConfigParser

Example auto building ConfigParser data with sections and key/values

data_to_build = {'section1': {'key1': 1}, 'section2': {'key2': 2}}

data = maci.inibuildauto(data_to_build)

In this example, we created a simple dictionary representing sections with key names and their values and assigned the data to a variable, then passed the dict data as an argument to the inibuildauto function to build the ini data and assign the returned data to a variable.

dictionary structure

As shown in the example above, in order to auto-build the ini data for your ConfigParser object, your dictionary must follow a specific structure. The structure is as follows:

  • All top level key names in dict are sections

  • All values of each section must contain a dict with key/value pairs

Example structure unpacked

{ 
    'section1': {
        'key1': 'value1'
    },
    'section2': {
        'key2': 'value2'
    }
}

Values can be anything, but when they are dumped to a file and loaded back in, they will be loaded as a string type in their string representation (See iniload)

Note: If your sub-value contains a NoneType, this function will auto-convert that to a string representation for you as the underlying library does not support None. More information on using ConfigParser data: Youtube Video Search: https://www.youtube.com/results?search_query=python+configparser Documentation: https://docs.python.org/3/library/configparser.html

parameters & arguments

Describes all parameter functionality and accepted data types

data: dict[str, dict[str, Any]]

First and only required positional argument. Accepts dictionaries

Use this parameter to pass in the data you want to build out the ConfigParser object.

This function uses the native configparser library shipped with the python standard library for its underlying functionality. For more information on the configparser library, visit: https://docs.python.org/3/library/configparser.html

Last updated