RE: configparser get non-existent boolean

Anders Munch <[email protected]>
Newsgroups gmane.comp.python.general
Message-ID <VI1PR05MB10680C2A5356AD1484F4A20A6B441A@VI1PR05MB10680.eurprd05.prod.outlook.com>
Rob Cliffe wrote:
> I was surprised to find that in configparser, getboolean() does not raise KeyError for a non-existent config parameter.
> Is there a good reason for this?

History and backwards compatibility.  The configparser module has some years on it.

The rationale for this sort of thing is this: It's a common enough case for a file
to not contain a key that writing a try/expect can be seen as too cumbersome compared to 
an "is None" test.

Reasonable people may disagree, preferring a KeyError if no fallback is
provided, but it's too late to change now.

regards, Anders
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.