escaping - Working with Parameters containing Escaped Characters in Python Config file -
i have config file i'm reading using following code:
import configparser cp config = cp.configparser() config.read('mtxxx.ini') mt=identify_mt(msgtext) schema_file = config.get(mt,'kbfile') fold_text = config.get(mt,'fold')
the relevant section of config file looks this:
[536] kbfile=mt536.kb fold=:16s:transdet\n
later try find text contained in dictionary matches 'fold' parameter, i've found if find text using following function:
def test (find_text) return {k k, v in dictionary.items() if find_text in v}
i different results if call function in 1 of 2 ways:
test(fold_text)
fails find data want, but:
test(':16s:transdet\n')
returns results know there.
and, if print content of dictionary, can see is, expected, shown as
:16s:transdet\n
so, matches when enter search text directly, doesn't find match when load same text in config file.
i'm guessing there's magic being applied here when reading/handling \n character pattern in config file, don't know how work way want to.
i want able parameterise using escape characters seems i'm blocked doing due internal mechanism.
is there switch can apply config reader, or parsing can behavior want? or perhaps there's alternate solution. find configparser module convenient use, perhaps limitation requires alternative, or self-built module lift data out of parameter file.
Comments
Post a Comment