Comments in ConfigParser module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joel Andres Granados

    #1

    Comments in ConfigParser module

    Hi list:

    I have run across a situation with ConfigParser Module. It refers to
    the comments in the configuration filed. According to the
    http://docs.python.org/dev/lib/module-ConfigParser.html it states that
    lines starting with "#" and ";" are ignored.
    So lines like:
    ; comment
    # comment
    are considered comments. So far so good.

    The module also allows the comments to appear in the same line as the
    "name = value" constructs. The only difference being that this is only
    possible with ";" and not with "#" character. I did not see this in the
    documentation but this is how it is behaving.
    So while the following line takes the comment as a comment.
    *name = value ; comment*
    the next line does not result in the same behavior.
    *name = value # comment*
    the name element would have "value # comment" as its value, when what I
    really want is for "comment" to be taken as a comment.

    QUESTION...So the question is:
    Can you use "#" and ";" as comment characters? and if so why does the
    "#" not apply for the same situations as the ";"? I'm working with fc7
    (I synced it sometime last week) and python 2.5 (r25:51908, Feb 13 2007,
    09:13:20)

    Any comment greatly appreciated....


    Just for reference:
    On the RFC 822 <http://www.faqs.org/rfcs/rfc822.html(a document
    referenced in the documentation) there is a mention of ";" being used as
    comment character but not necessarily at the beginning of the line.
    So anything that comes after the ";" is ignored.
    name = value ; comment (";comment" would be ignored)



  • James Stroud

    #2
    Re: Comments in ConfigParser module

    Joel Andres Granados wrote:
    Hi list:
    Any comment greatly appreciated....
    Very clever.

    Comment

    • Gabriel Genellina

      #3
      Re: Comments in ConfigParser module

      Joel Andres Granados wrote:
      The module also allows the comments to appear in the same line as the
      "name = value" constructs. The only difference being that this is only
      possible with ";" and not with "#" character. I did not see this in the
      documentation but this is how it is behaving.
      Yes, it's not documented. There is only a comment in the source code:

      # ';' is a comment delimiter only if it
      follows
      # a spacing character

      I think it's either a bug in the code or in the documentation.
      QUESTION...So the question is:
      Can you use "#" and ";" as comment characters? and if so why does the
      "#" not apply for the same situations as the ";"?
      If you follow the documentation, comments are ONLY allowed to start a
      line.
      The actual implementation discards any text following a <space>;
      sequence.
      Just for reference:
      On the RFC 822 <http://www.faqs.org/rfcs/rfc822.html(a document
      referenced in the documentation) there is a mention of ";" being used as
      comment character but not necessarily at the beginning of the line.
      RFC822 uses ";" to include comments in the syntax rules, not for
      comments in the actual message headers (parenthesis are used there).

      --
      Gabriel Genellina

      Comment

      • James Stroud

        #4
        Re: Comments in ConfigParser module

        Joel Granados wrote:
        >
        >
        On 4/6/07, *James Stroud* <jstroud@mbi.uc la.edu
        <mailto:jstroud @mbi.ucla.edu>w rote:
        >
        Joel Andres Granados wrote:
        Hi list:
        Any comment greatly appreciated....
        >
        Very clever.
        --

        <http://mail.python.org/mailman/listinfo/python-list>
        >
        >
        clever ???
        Well I would expect that the ";" character to behave the same way that
        the "#", as they are both characters that come before a comment. But it
        doesn't. So I'm missing something here. Why is the different behavior
        clever?
        >
        --
        Joel Andrés Granados
        Medellín Colombia
        --
        jgranad1@eafit. edu.co <mailto:jgranad 1@eafit.edu.co>
        joel.granados@i eee.org <mailto:joel.gr anados@ieee.org >
        I was referring to his asking for "comments" in a post about "comments".
        I thought this was a clever way to conclude. I have no idea why the
        behavior of the module is the way it is. Seems like a bug to me, but I
        have not read the official .ini file specification, so I'm not sure its
        working correctly.

        Cheers,

        James

        Comment

        • Gabriel Genellina

          #5
          Re: Comments in ConfigParser module

          En Sun, 08 Apr 2007 06:17:46 -0300, Joel Granados
          <joel.granados@ gmail.comescrib ió:
          On 7 Apr 2007 13:19:06 -0700, Gabriel Genellina <gagsl-py2@yahoo.com.a r>
          wrote:
          >>
          >Joel Andres Granados wrote:
          >>
          The module also allows the comments to appear in the same line as the
          "name = value" constructs. The only difference being that this is
          >only
          possible with ";" and not with "#" character. I did not see this in
          >the
          documentation but this is how it is behaving.
          >>
          >Yes, it's not documented. There is only a comment in the source code:
          >>
          > # ';' is a comment delimiter only if it
          >follows
          > # a spacing character
          >>
          >I think it's either a bug in the code or in the documentation.
          >
          Yep, IMO its a weirdness in the behavior that is not documented.
          It was a bit hard, but I finally found the original Windows ini-file
          specification at <http://www.microsoft.c om/technet/archive/wfw/2_ch6.mspx>
          where you can see ; used as comment delimiter.
          ConfigParser tries to handle both RFC822-like headers (with name: value,
          including continuation lines, but ignoring almost everything else in the
          syntax) and ini files (with ; as comments), plus some unique features like
          # comments and "rem" lines removal (?). That is, it tries to cover a lot
          of formats without a clear specification.
          Add wrong defaults usage, and the need for SafeConfigParse r, and some
          other gotchas... then switch to use alternative implementations like
          ConfigObj <http://www.voidspace.o rg.uk/python/configobj.html>

          --
          Gabriel Genellina

          Comment

          Working...