ConfigParser options spanning more than one line

Discussion in 'Python' started by Josh Close, Aug 16, 2004.

  1. Josh Close

    Josh Close Guest

    I'm using ConfigParser and I can't seem to get a config option to span
    more than one line.

    [MyConfig]
    var = blah blah blah\
    blah continued

    Putting the '\' doesn't work

    Is there a way to do that? Or do I have to deal with having a huge
    long string all on one line?

    -Josh
    Josh Close, Aug 16, 2004
    #1
    1. Advertising

  2. On 2004-08-16, Josh Close <> wrote:
    > I'm using ConfigParser and I can't seem to get a config option to span
    > more than one line.
    >
    > [MyConfig]
    > var = blah blah blah\
    > blah continued
    >
    > Putting the '\' doesn't work
    >
    > Is there a way to do that? Or do I have to deal with having a huge
    > long string all on one line?


    Simply do:

    [MyConfig]
    var = blah blah blah
    blah continued

    without the '\'. Indentation continues the line.

    /npat
    Nick Patavalis, Aug 16, 2004
    #2
    1. Advertising

  3. > I'm using ConfigParser and I can't seem to get a config option to span
    > more than one line.


    >>> from ConfigParser import ConfigParser
    >>> from StringIO import StringIO
    >>> s = StringIO("[a]\n"

    .... "b = 123\n"
    .... " 456")
    >>> c=ConfigParser()
    >>> c.readfp(s)
    >>> c.get('a','b')

    '123\n456'

    In other words, any line with a leading whitespace is considered a
    continuation line, and the leading whitespace is stripped from the value
    (but the carriage return is left in).

    HTH,
    -param
    Paramjit Oberoi, Aug 16, 2004
    #3
  4. Josh Close

    Josh Close Guest

    That works, I guess I'll just have to remove the \n from the variable then.

    -Josh

    On Mon, 16 Aug 2004 13:31:03 -0500, Paramjit Oberoi
    <> wrote:
    > > I'm using ConfigParser and I can't seem to get a config option to span
    > > more than one line.

    >
    > >>> from ConfigParser import ConfigParser
    > >>> from StringIO import StringIO
    > >>> s = StringIO("[a]\n"

    > .... "b = 123\n"
    > .... " 456")
    > >>> c=ConfigParser()
    > >>> c.readfp(s)
    > >>> c.get('a','b')

    > '123\n456'
    >
    > In other words, any line with a leading whitespace is considered a
    > continuation line, and the leading whitespace is stripped from the value
    > (but the carriage return is left in).
    >
    > HTH,
    > -param
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Josh Close, Aug 16, 2004
    #4
    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. Matthew Wilson
    Replies:
    1
    Views:
    855
    Jarek Zgoda
    Nov 23, 2003
  2. Replies:
    3
    Views:
    416
  3. Merciadri Luca
    Replies:
    4
    Views:
    800
  4. Steven D'Aprano
    Replies:
    0
    Views:
    79
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    73
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page