A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-November/029987.html below:

[Python-Dev] ConfigParser with a single section

[Python-Dev] ConfigParser with a single section [Python-Dev] ConfigParser with a single sectionFredrik Lundh fredrik@pythonware.com
Fri, 8 Nov 2002 00:40:25 +0100
Gustavo Niemeyer wrote:

> The most compeling reason I could see is:
> 
> >>> import ConfigParser
> >>> cfg = ConfigParser.ConfigParser(singlesection="shell")
> >>> cfg.read("/etc/sysconfig/network-scripts/ifcfg-lo")
> >>> cfg.get("shell", "ipaddr")
> '127.0.0.1'

don't forget that you can subclass stuff in Python:

import ConfigParser, StringIO

class MyConfigParser(ConfigParser.ConfigParser):
    def read(self, filename):
        try:
            text = open(filename).read()
        except IOError:
            pass
        else:
            file = StringIO.StringIO("[shell]\n" + text)
            self.readfp(file, filename)

cfg = MyConfigParser()
cfg.read("/etc/sysconfig/network-scripts/ifcfg-lo")
cfg.get("shell", "ipaddr")

</F>




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4