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 =  192.168.0.0
proxy_server = 192.168.0.100

And script:

# file: name_dest.py
import cfgparse
c = cfgparse.ConfigParser()
c.add_file('name_dest.ini')
c.add_option('mail_server')
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 = 192.168.0.0
Proxy Server IP Address = 192.168.0.100