[Tutor] find and replace relative to an nearby search string in a file
A.T.Hofkamp
a.t.hofkamp at tue.nl
Mon Jul 13 09:00:22 CEST 2009
Pete O'Connell wrote:
>
> Write {
> file /Volumes/raid0/Z353_002_comp_v27.%04d.cin
> file_type cin
> name Write1
> xpos 13762
> ypos -364
> }
The simplest approach imho is to parse the input with a proper parser, eg PLY
or pyparsing.
If you want to do the parsing manually, I'd start by classifying each line
manually to be one of
<empty>
"Write" "{"
<identifier> <argument>
"}"
and then collect the lines of each group to eg a dict (if there are no
duplicate keys, and order is not relevent).
In both cases, you'll end up with a list of collected groups.
Once you have that, you can do your processing.
Finally, convert the groups back to text.
Albert
More information about the Tutor
mailing list