Comments in configuration files
Tim Daneliuk
tundra at tundraware.com
Sat Jan 22 06:08:21 EST 2005
Pierre Quentel wrote:
> Bonjour,
>
> I am developing an application and I have a configuration file with a
> lot of comments to help the application users understand what the
> options mean
>
> I would like it to be editable, through a web browser or a GUI
> application. With ConfigParser I can read the configuration file and
> edit the options, but when I write the result all the comments are lost
>
> Are there modules that work on the same kind of ini files (for the needs
> of my application, I prefer this format to XML or YAML) and don't remove
> the comments ?
>
> TIA,
> Pierre
The latest incarnation of 'tconfpy' I just released will get you close:
http://www.tundraware.com/Software/tconfpy
This program can read a configuration either from memory (a list) or a file.
So you could:
1) Read the file into an in-memory list (including the comments).
2) Pass the list to the parser, which would return a populated symbol
table.
3) Use your application to read the current values of the symbols from
the symbol table.
4) Modify the values in the symbol table as desired.
5) Map the new values in the symbol table back into the original list where
the values were set intitially (this is the part that would take some work).
6) Write the list back to disk.
Note that the semantics of feature of 'tconfpy' are substantially different
than 'ConfigParser', and the languages recognized by each are quite different
as well. It is probably fair to say that 'tconfpy' recognizes a superset
of the language recognized by 'ConfigParser'. But you have to be
careful because the semantics are somewhat different.
--
----------------------------------------------------------------------------
Tim Daneliuk tundra at tundraware.com
PGP Key: http://www.tundraware.com/PGP/
More information about the Python-list
mailing list