|
From: Michael F. <fuz...@vo...> - 2009-03-06 20:33:41
|
Marc Tompkins wrote:
> On Sun, Mar 1, 2009 at 12:12 PM, Marc Tompkins
> <mar...@gm... <mailto:mar...@gm...>> wrote:
>
> There aren't any "real" quotes in this file - is there any way to
> tell ConfigObj to ignore any single-quote characters it finds? If
> not, any clever ideas for a workaround? I did think of replacing
> "'" with "-" or something, but there are plenty of contractions in
> this file, and "doesn-t" doesn't look very pretty. On the other
> hand, searching for all matched pairs of quotes that appear in the
> same data item would require me to... well, to re-invent much of
> the guts of ConfigObj itself, no?
>
>
> I came up with an ugly workaround - actually, it's fine for my
> purposes, but typographically wrong - I'm replacing all the
> apostrophes with backticks. I'm hoping my users won't notice.
> Actually, of course, I could do another replacement just before
> printing; I might do that later on if I'm bored.
I'm afraid that you're trying to read a configuration file format that
ConfigObj wasn't designed to work with. A different ConfigObj could have
a pluggable parser with a flexible grammar, but I don't have time to
write that one...
In the meantime your two phase replace sounds like our only option. You
could replace each apostrophe with a unique character combination and
then us walk() to replace every occurrence again after reading.
Michael Foord
>
> Here's my first pass at the problem:
>
> class mcrCodes(object):
>
> def __init__(self, codeFileName="C:/temp/Codes.ini"):
> with open(codeFileName,'r') as inFile:
> tmpCodes = inFile.readlines()
> releaseDate = tmpCodes.pop(0)
> for index, line in enumerate(tmpCodes):
> tmpCodes[index] = line.replace("\'", "`")
> self.codes = ConfigObj(tmpCodes, raise_errors=True,
> list_values=False)
>
> codeFile = mcrCodes()
> for code, val in codeFile.codes.iteritems():
> print code, val
>
>
> --
> www.fsrtechnologies.com <http://www.fsrtechnologies.com>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> ------------------------------------------------------------------------
>
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>
--
http://www.ironpythoninaction.com/
|