Noob confused by ConfigParser defaults

Ben Finney ben+python at benfinney.id.au
Mon Feb 20 02:39:40 EST 2017


Ian Pilcher <arequipeno at gmail.com> writes:

> How do a set a default for option-1 *only* in section-1?

I think you misinderstand the semantics of what ‘configparser’ expects
<URL:https://docs.python.org/3/library/configparser.html#configparser-objects>:

    Default values […] are used in interpolation if an option used is
    not defined elsewhere.

    When default_section is given, it specifies the name for the special
    section holding default values for other sections and interpolation
    purposes (normally named "DEFAULT").

The default values are a special pseudo-section that holds defaults for
the named options *anywhere else* in the configuration. It's not done
per-section, it's done for the entire configuration input.

This is IIUC because of the long-standing semantics of the format that
inspired the ConfigParser behaviour.

-- 
 \      “Software patents provide one more means of controlling access |
  `\      to information. They are the tool of choice for the internet |
_o__)                                     highwayman.” —Anthony Taylor |
Ben Finney




More information about the Python-list mailing list