ConfigParser.getboolean() fails if it falls back to a default value, and the value passed in was a boolean object (instead of a string) because it unconditionally does v.lower(). This should be fixed; there's something un-Pythonic about expecting a boolean value but not being able to actually provide a boolean as the default. I've attached a patch (against 2.3.4c1; should apply to 2.3.4, I think) which makes the v.lower() conditional on v being a string, and adds bool(True), bool(False), int(1), and int(0) to _boolean_states. Alternative resolution: change the documentation to specify that /only/ strings should be passed in the defaults dictionary. Less Pythonic.
Logged In: YES user_id=80475 The method is functioning exactly as documented. Changing this to a feature request. FWIW, it seems reasonable to allow a boolean to be passed in a default; however, calling it unpythonic is a bit extreme since the whole API is designed to work with text arguments. My solution would be to just add two lines after the self.get: if isinstance(v, bool): return v
Logged In: YES user_id=29957 I don't see any reason to not allow a boolean as a default. Raymond's solution seems like a good one to me. Anyone object?
With the latest python, get() itself fails with boolean value default. I tried with this script: ------------- from ConfigParser import ConfigParser cfg = ConfigParser({'var':True}) cfg.add_section('test_section') print cfg.getboolean('test_section', 'var') ------------- and it results in ------------- Traceback (most recent call last): File "t.py", line 4, in print cfg.getboolean('test_section', 'var') File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py", line 349, in getboolean v = self.get(section, option) File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py", line 545, in get return self._interpolate(section, option, value, d) File "/localhome/raghu/localwork/cpython/trunk/Lib/ConfigParser.py", line 585, in _interpolate if "%(" in value: TypeError: argument of type 'bool' is not iterable ------------- I doubt if it is worth fixing the OP's issue considering that _interpolate is assuming the value to be string. Can I close this issue?