|
From: Mark L. <mw...@po...> - 2006-02-23 09:27:40
|
According to the docs: http://www.voidspace.org.uk/python/configobj.html#default-values "You can set a default value in your check. If the value is missing from the config file then this value will be used instead." I think I'm making an incorrect assumption about retrieving default values from the dict, as illustrated here: File test.spec containing only: key1 = integer(0, 30, default=15) key2 = integer(default=15) File test.conf containing only: key1 = 5 >>> c = ConfigObj( 'test.conf', configspec='test.spec' ) >>> c {'key1': '5'} >>> c.configspec {'key2': 'integer(default=15)', 'key1': 'integer(0, 30, default=15)'} >>> c['key1'] '5' >>> c['key2'] Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\Python24\Lib\site-packages\configobj.py", line 337, in __getitem__ val = dict.__getitem__(self, key) KeyError: 'key2' Shouldn't this return the default value, in this case 15? Is there a different method I should be using for retrieving values? I can't find anything in the documentation or via introspection. I specifically want the defaults specified in an external file and not in the code using something like c.get('key2',15). I'm using configobj version 4.2.0beta2 Cheers, -Mark |