How do I use the config parser?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • noagbodjivictor@gmail.com

    #1

    How do I use the config parser?

    Hi,
    I need a specific example. I have seen the docs, but I don't all the
    stuffs there.

    So basically, I need my config file to be created and read by my
    script.

    Here is a snippet

    # read old actions
    from ConfigParser import ConfigParser

    fp = open(makepath(' App\qt_actions. conf'))
    configdict = ConfigParser()
    configdict.read fp(fp)


    Now I want to know how to read a section, a section attribute's value,
    and to write thoses back after reading.

    Thanks

  • Rob Williscroft

    #2
    Re: How do I use the config parser?

    wrote in news:1178392410 .866037.179950@ e65g2000hsc.goo glegroups.com in
    comp.lang.pytho n:
    Hi,
    I need a specific example. I have seen the docs, but I don't all the
    stuffs there.
    >
    from ConfigParser import ConfigParser
    Now I want to know how to read a section, a section attribute's value,
    and to write thoses back after reading.
    >
    ConfigParser is derived from RawConfigParser , so you need
    to look at RawConfigParser 's docs here:




    Rob.
    --

    Comment

    • Fuzzyman

      #3
      Re: How do I use the config parser?

      On May 5, 8:13 pm, noagbodjivic... @gmail.com wrote:
      Hi,
      I need a specific example. I have seen the docs, but I don't all the
      stuffs there.
      >
      So basically, I need my config file to be created and read by my
      script.
      >
      Here is a snippet
      >
      # read old actions
      from ConfigParser import ConfigParser
      >
      fp = open(makepath(' App\qt_actions. conf'))
      configdict = ConfigParser()
      configdict.read fp(fp)
      >
      Now I want to know how to read a section, a section attribute's value,
      and to write thoses back after reading.
      >
      You could do it simply with ConfigObj ( http://www.voidspace.org.uk/python/configobj.html
      ):

      from configobj import ConfigObj

      config = ConfigObj(filen ame)
      section = config['Section Name']
      value = section['value']

      .....

      section['value'] = newValue
      config.write()

      All the best,


      Fuzzyman
      http://www.voidspace.org.uk/python/articles.shtml

      Thanks

      Comment

      • Larry Bates

        #4
        Re: How do I use the config parser?

        noagbodjivictor @gmail.com wrote:
        Hi,
        I need a specific example. I have seen the docs, but I don't all the
        stuffs there.
        >
        So basically, I need my config file to be created and read by my
        script.
        >
        Here is a snippet
        >
        # read old actions
        from ConfigParser import ConfigParser
        >
        fp = open(makepath(' App\qt_actions. conf'))
        configdict = ConfigParser()
        configdict.read fp(fp)
        >
        >
        Now I want to know how to read a section, a section attribute's value,
        and to write thoses back after reading.
        >
        Thanks
        >
        The best place to start is always:

        import ConfigParser
        help(ConfigPars er)


        Example:

        section='INIT'
        option='logfile '

        logfile=configd ict.get(section , option)

        most of the methods are self explanitory.

        -Larry

        Comment

        Working...