I have a CsvWriter class that inherits from a Writer class. The Writer class has a function getInfo that I want to use in multiple ‘child’ classes. But when I call the getInfo function from the CsvWriter class I get this error:
TypeError: unbound method getInfo() must be called with Writer instance as first argument (got Element instance instead)
So because the Writer class hasn’t been intansiated yet, I can’t call getInfo. But I don’t want to instantiate it (I think), because I want to call it from a ‘child’ class. How can I call that function from CsVwriter()?
Below are the two classes:
class Writer():
def __init__(self, path, readerInstance):
self.path = path
self.readerInstance = readerInstance
return
def getInfo(self, element):
print element
class CsvWriter(Writer):
def __init__(self,path, readerInstance):
self.path = path
self.readerInstance = readerInstance
for feature in readerInstance.getFeatures():
Writer.getInfo(feature)
return
I run them like this:
filePath = '/homes/ndeklein/test.featureXML'
elements = featXML.Reader(filePath)
featXML.CsvWriter('test.csv', elements)
Replace
Writer.getInfo()withself.getInfo().