|
From: Michael F. <fuz...@vo...> - 2008-09-21 19:25:36
|
Jeffrey Barish wrote: > On Sunday 21 September 2008 11:30:36 Michael Foord wrote: > >> Jeffrey Barish wrote: >> >>> On Sunday 21 September 2008 04:17:50 Michael Foord wrote: >>> >>>> Jeffrey Barish wrote: >>>> >>>>> On Saturday 20 September 2008 18:55:17 Jeffrey Barish wrote: >>>>> >>>>>> Configobj was working fine until I switched to using unrepr mode. Now >>>>>> it works fine on one platform, but on another the same code produces >>>>>> the following error: >>>>>> >>>>>> ... >>>>>> File "/usr/lib/python2.5/site-packages/configobj.py", line 1272, in >>>>>> __init__ self._load(infile, configspec) >>>>>> File "/usr/lib/python2.5/site-packages/configobj.py", line 1355, in >>>>>> _load raise error >>>>>> configobj.ConfigObjError: Parsing failed with several errors. >>>>>> First error at line 3. >>>>>> >>>>>> Line 3 is: >>>>>> >>>>>> v = 0.77304964539007093 >>>>>> >>>>>> I am using version 4.5.3 on python 2.5.2. Considering that the same >>>>>> rc file works fine on the other platform, I am at a loss as to what to >>>>>> do. Any suggestions? >>>>>> >>>>> The problem appears to arise because there is no compiler module on >>>>> this platform (Nokia N800). >>>>> >>>>> Do I have any options other than returning to code like >>>>> >>>>> if x == 'True' >>>>> >>>> unrepr mode relies on the compiler module - so it won't work on a >>>> platform that doesn't provide it. >>>> >>>> You could use validate and a configspec to convert types instead. >>>> >>>> >>>> Michael >>>> >>> OK. I learned how to use validate. It works nicely for converting types >>> and I am also doing range checking, so it's a better solution anyway. >>> >>> One problem, though. In my configuration file I have a section with >>> colors, but I don't know a priori what colors it will contain. For >>> example: >>> >>> [colors] >>> color1 = [143, 188, 143] >>> color2 = [70, 130, 180] >>> >>> and so on. Since I don't know what the keys are going to be, I presume >>> that there is no way for me to validate the entries. Is that true? It >>> would be nice to be able to test that values are between 0 and 255 and to >>> convert the strings to integers and the brackets to a list. Currently I >>> am doing >>> >>> color1 = 143, 188, 143 >>> >>> and not validating. >>> >> You're correct that ConfigObj doesn't support validating arbitrary >> entries in a section. It is a worthy feature request though (perhaps "* >> = check()"). >> >> I'll add it to my list - but as I am *still* finishing a book it will be >> quicker if someone else implements it. It will need to be in the >> ConfigObj.validate method rather than in the validate module. >> >> Michael >> > > Here's a worse problem: after using config.reload(), all values revert to > strings. I have to revalidate after every reload to get values back into > their correct types. > Hmmm... that sounds like correct behaviour to me. Validation is an explicit step. Michael -- http://www.ironpythoninaction.com/ http://www.voidspace.org.uk/ http://www.trypython.org/ http://www.ironpython.info/ http://www.theotherdelia.co.uk/ http://www.resolverhacks.net/ |