|
From: Marc T. <mar...@gm...> - 2009-03-02 02:22:01
|
On Sun, Mar 1, 2009 at 12:12 PM, Marc Tompkins <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.
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
|