Comments in configuration files

Discussion in 'Python' started by Pierre Quentel, Jan 22, 2005.

  1. 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
    Pierre Quentel, Jan 22, 2005
    #1
    1. Advertising

  2. Pierre Quentel

    Tim Daneliuk Guest

    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
    PGP Key: http://www.tundraware.com/PGP/
    Tim Daneliuk, Jan 22, 2005
    #2
    1. Advertising

  3. Pierre Quentel

    alex23 Guest

    > 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

    Hey Pierre,

    I came across a good review of a number of possible solutions for this
    at http://www.python.org/moin/ConfigParserShootout
    Hope it helps.

    - alex23
    alex23, Jan 23, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    810
  2. Stephan Koser
    Replies:
    3
    Views:
    671
    Juha Laiho
    Dec 7, 2004
  3. Replies:
    0
    Views:
    1,113
  4. Monk
    Replies:
    10
    Views:
    1,458
    Michael Wojcik
    Apr 20, 2005
  5. Replies:
    4
    Views:
    600
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page