Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Tim Chase
On 2017-02-21 00:04, Peter Otten wrote: > Tim Chase wrote: >> On 2017-02-20 10:45, Peter Otten wrote: >>> value = parser.get("section-1", "option-1", fallback="default >>> value") >> >> Huh. Do you remember when this was added? > > I don't use configparser regularly, so I had to look around myse

Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Peter Otten
Tim Chase wrote: > On 2017-02-20 10:45, Peter Otten wrote: >> value = parser.get("section-1", "option-1", fallback="default >> value") > > Huh. Do you remember when this was added? I see it in the 3.x docs, > but not the 2.x docs. I remember writing my own wrappers multiple > times for exactly

Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Tim Chase
On 2017-02-20 10:45, Peter Otten wrote: > value = parser.get("section-1", "option-1", fallback="default > value") Huh. Do you remember when this was added? I see it in the 3.x docs, but not the 2.x docs. I remember writing my own wrappers multiple times for exactly these purposes, even to the

Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Ian Pilcher
On 02/20/2017 03:45 AM, Peter Otten wrote: You can provide a default value in your code with parser = configparser.ConfigParser() parser.read(configfile) value = parser.get("section-1", "option-1", fallback="default value") Perfect. Thank you! -- =

Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Ian Pilcher
On 02/20/2017 01:39 AM, Ben Finney wrote: I think you misinderstand the semantics of what ‘configparser’ expects https://docs.python.org/3/library/configparser.html#configparser-objects>: You are absolutely correct. Thank you! -- ===

Re: Noob confused by ConfigParser defaults

2017-02-20 Thread Peter Otten
Ian Pilcher wrote: > I am trying to use ConfigParser for the first time (while also writing > my first quasi-serious Python program). Assume that I want to parse a > a configuration file of the following form: > >[section-1] >option-1 = value1 >option-2 = value2 > >[section-2] >

Re: Noob confused by ConfigParser defaults

2017-02-19 Thread Ben Finney
Ian Pilcher writes: > How do a set a default for option-1 *only* in section-1? I think you misinderstand the semantics of what ‘configparser’ expects https://docs.python.org/3/library/configparser.html#configparser-objects>: Default values […] are used in interpolation if an option used is

Noob confused by ConfigParser defaults

2017-02-19 Thread Ian Pilcher
I am trying to use ConfigParser for the first time (while also writing my first quasi-serious Python program). Assume that I want to parse a a configuration file of the following form: [section-1] option-1 = value1 option-2 = value2 [section-2] option-1 = value3 option-2 = value4 H