Re: [Pyparsing] How to get to a specific block of text I need
Brought to you by:
ptmcg
From: Ralph C. <ra...@in...> - 2017-02-26 12:11:05
|
Hi Malahal, > export { > path = path1; > key2 = value2; > client { > clientid = value3; > key4 = value4; > } > client { > clientid = value6; > } > } ... > Given an export path, I would like to fetch the corresponding export > block. This sounds more like a Python programming problem than Pyparsing. You want to build a `dict' indexed by an export's `path' as you're parsing. https://docs.python.org/3/tutorial/datastructures.html#dictionaries The value for a key would be a data of your design that describes an export. Lookup would then be exports['path1'] > Similarly, for a given path and clientid, I would like to get the > corresponding "client" block quickly Same here, except you have a dict of dicts. clients['path1']['value3'] Or you might make the information available as part of your exports dict if the value was an object with a `clients' attribute that was a dict. exports['path1'].clients['value3'] -- Cheers, Ralph. https://plus.google.com/+RalphCorderoy |