2.3.1 Name and Destination

The name string argument of the add_option() method is used to specify the name of the option setting to be obtained from the configuration file. name is required and is case sensitive, the option name in the configuration file must exactly match the name argument.

The parse() method returns an object with attributes set to the option settings specified using the add_option() method. The dest string argument is used to control the name of the attribute. If dest argument is not present, the name is used as the attribute name. Each option added must have a unique destination attribute name.

For example:

# file: name_dest.ini
mail_server =
proxy_server =

And script:

# file: name_dest.py
import cfgparse
c = cfgparse.ConfigParser()
c.add_option('proxy_server', dest='proxy')
opts = c.parse()
print 'Mail Server IP Address =',opts.mail_server
print 'Proxy Server IP Address =',opts.proxy

Results in:

$ python name_dest.py
Mail Server IP Address =
Proxy Server IP Address =