0

So I am trying to create a class that will have already read in the file and have all functions of configparser plus a few more. Code looks like this:

import configparser
class dkconfig(configparser):
    def __init__(self):
        self.clusterini = os.path.abspath("..\\cluster.ini")
        super(dkconfig,self).__init__(allow_no_value=True)
        if os.path.exists(self.clusterini):
            self.read(self.clusterini)


    def getHostnames(self):
        hostnames = {}
        for sec in self.config.sections():
            if sec.startswith("node"):
                hostnames[sec] = self.config.get(sec, "hostname")
        return hostnames

And its called from another script like so:

config = dkconfig()
names = config.getHostnames()
opts = config.options("node1")

The error says: TypeError: module.__init__() takes at most 2 arguments (3 given) What am I missing and how can I have all instances of the "dkconfig" object already have the "cluster.ini" file read-in during construction?

mawueth
  • 2,668
  • 1
  • 14
  • 12
beeryardtech
  • 605
  • 1
  • 4
  • 15

1 Answers1

3

Well, the immediate cause of the error is that you're trying to inherit from the configparser module. You need to inherit from the class, not the module.

class dkconfig(configparser.ConfigParser):
    # ....
senderle
  • 145,869
  • 36
  • 209
  • 233