6.2.2 ConfigSection Objects

class ConfigSection(name, data={ } )

Instantiate a ConfigSection object.

name  is the name of the section.

data , if specified, is the dictionary of data to initalize the section contents with.

ConfigSection objects are rarely instantiated manually. They are generally created using the ConfigManager API (either the direct methods or the Python dictionary syntax).

data

dictionary that contains the option instances. This is only accessed if you want to retrieve the real option instances. Normally, you would use standard dictionary key access syntax on the section itself to retrieve the option values.

name

the name given to the section.

copy()

make a deep copy of the section object.

defaults()

return the dictionary of default options associated with the parent ConfigManager.

get(option, raw=0, vars={ } )

retrieve the value of option . Setting raw  to true prevents any string interpolation from occurring in that value. vars  is a dictionary of addition value to use when interpolating values into the option.

Note: You can alsouse the alternative dictionary syntax: section.get(option).

getboolean(section, option )

retrieve the specified value and cast it to a boolean

__getitem__(key )

retrieve the value of an option. This method allows you to use Python’s dictionary syntax on a section as shown below.

# Print the value of the 'optionname' option
print mysection['optionname'] 

getint(section, option )

retrieve the specified value and cast it to and integer

getfloat(section, option )

retrieve the specified value and cast it to a float

getraw(section, option )

return the raw (i.e. un-interpolated) value of the option

parent

a reference to the parent ConfigManager object.

__repr__()

return a string containing an INI file representation of the section.

set(option, value )

create a new option or set an existing option with the name option  and the value of value . If the given value is already an option instance, it is simply inserted into the section. If it is not an option instance, an appropriate type of option is chosen for the given type.

__setitem__(key, value )

create a new option or set an existing option with the name key  and the value of value . This method allows you to use Python’s dictionary syntax to set options as shown below.

# Create a new option called 'optionname'
mysection['optionname'] = 10

__str__()

return a string containing an INI file representation of the section. Options set from Python code are not included in this representation.

to_string([source])

return a string containing an INI file representation of the section. The source  option allows you to only display options from certain sources. See the ConfigManager.source() method for more information.