|
From: David B. <da...@gm...> - 2008-08-10 23:22:39
|
Thanks, that will work for me. For future reference is replacing a function like i mentioned previously a bad practice? (Assuming i cant find the proper way to do it like you showed me or there is not one available.) Thanks so much for your assistance. Michael Foord wrote: > David B. wrote: > >> Apparently i was looking at the documentation for an older version of configobj. >> >> http://www.voidspace.org.uk/python/configobj3.html#exceptions >> >> My apologies. However, I still need a way to prevent configobj from stopping when it finds a duplicate key word entry. The link you posted says that the default for raise_errors is False and that parsing should continue. However for my program it stops parsing and the program exits. I did find that i can define the following in my program and it works for me: >> >> >> > > Although ConfigObj continues parsing it still raises an exception when > it finishes parsing. > > Therefore instead of your code you could use: > > try: > > config = ConfigObj(filename) > except ConfigObjError, e: > config = e.config > > This ignores the error and uses whatever ConfigObj managed to find. > > Michael > > >> def _handle_error(self, text, ErrorClass, infile, cur_index): >> ##the next two lines i added to stop duplicate >> ##entries from causing problems >> if ErrorClass ==configobj.DuplicateError: >> return >> ##this is the end of the changes i made. >> line = infile[cur_index] >> cur_index += 1 >> message = text % cur_index >> error = ErrorClass(message, cur_index, line) >> if self.raise_errors: >> # raise the error - parsing stops here >> raise error >> # store the error >> # reraise when parsing has finished >> self._errors.append(error) >> configobj.ConfigObj._handle_error=_handle_error >> >> This works but im not sure that this is "good coding" practice. >> The following is the problem im am having. >> >> >>>>> x=configobj.ConfigObj("conf") >>>>> >>>>> >> Traceback (most recent call last): >> File "<stdin>", line 1, in <module> >> File "/var/lib/python-support/python2.5/configobj.py", line 1272, in __init__ >> self._load(infile, configspec) >> File "/var/lib/python-support/python2.5/configobj.py", line 1355, in _load >> raise error >> configobj.DuplicateError: Duplicate keyword name at line 3. >> >> the conf file looks like this: >> [conf] >> value1= workgroup >> value1=workgroup2 >> >> Any pointers would be appreciated. >> Thanks, >> David >> >> >> >> Michael Foord wrote: >> >> >>> David B. wrote: >>> >>> >>> >>>> Im trying to use the exceptionlist that is mentioned in the docs on the >>>> website to stop my program from erroring out if there is a duplicate >>>> value entered in the config file. However, when i try to do >>>> >>>> from configobj import exceptionlist >>>> >>>> like the website says to do, i get the following: >>>> >>>> >>> from configobj import exceptionlist >>>> Traceback (most recent call last): >>>> File "<stdin>", line 1, in <module> >>>> ImportError: cannot import name exceptionlist >>>> >>>> >>>> >>>> >>> ConfigObj doesn't define any 'exceptionlist', nor is it in the >>> documentation. Where are you getting this example from? >>> >>> The ConfigObj exceptions are documented at: >>> >>> http://www.voidspace.org.uk/python/configobj.html#exceptions >>> >>> Michael Foord >>> >>> >>> >>> >>>> can anyone help me? >>>> thanks. >>>> David. >>>> >>>> ------------------------------------------------------------------------- >>>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge >>>> Build the coolest Linux based applications with Moblin SDK & win great prizes >>>> Grand prize is a trip for two to an Open Source event anywhere in the world >>>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>>> _______________________________________________ >>>> Configobj-develop mailing list >>>> Con...@li... >>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>>> >>>> >>>> >>>> >>> -- >>> 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/ >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge >>> Build the coolest Linux based applications with Moblin SDK & win great prizes >>> Grand prize is a trip for two to an Open Source event anywhere in the world >>> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >>> _______________________________________________ >>> Configobj-develop mailing list >>> Con...@li... >>> https://lists.sourceforge.net/lists/listinfo/configobj-develop >>> . >>> >>> >>> >>> >> ------------------------------------------------------------------------- >> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge >> Build the coolest Linux based applications with Moblin SDK & win great prizes >> Grand prize is a trip for two to an Open Source event anywhere in the world >> http://moblin-contest.org/redirect.php?banner_id=100&url=/ >> _______________________________________________ >> Configobj-develop mailing list >> Con...@li... >> https://lists.sourceforge.net/lists/listinfo/configobj-develop >> >> > > > -- > 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/ > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge > Build the coolest Linux based applications with Moblin SDK & win great prizes > Grand prize is a trip for two to an Open Source event anywhere in the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > . > > |