I have an hmtl file that looks like:
...
<!-- Special_ID -->
<p> stuff1 </p>
<p> stuff2 </p>
<!-- /Special_ID -->
...
I have an INI file:
[general]
param=stuff1
stuff2
If the user edits the file and changes the param value to test, I want the html file to be changed to:
...
<!-- Special_ID -->
<p> test </p>
<!-- /Special_ID -->
...
Currently, what I'm doing is parsing the INI file (Python's ConfigParser) and then turning the section ("general") and option ("param") into a start and stop special id like in the examples above.
Then:
while we haven't found the start id:
just write a line to some temporary file
write our start id to the temp file
write out new value ("test") to the temp file # surround with <p>
loop through original file until we find the stop id
then write the stop id and the rest of the file to temp
replace original file with tmp file
Is there a smarter way of doing this?
Perhaps a Python module that already does this.
I also don't particularly like requiring the <!-- Special_ID -->, but I'm not using a web framework (just a simple app), so I can't just do a fancy <p py:for ...>... like in TurboGears.