I have read about new way to call ancestor's constructor via super(..).__init__() and wanted to use it. I have a directory dataset with three files: __init__.py
from .Dataset import Dataset from .CSVDataset import CSVDataset CSVDataset.py
import csv import numpy as np from dataset import Dataset class CSVDataset(Dataset): """ reads dataset from csv file """ def __init__(self, file): Dataset.__init__(self) #super(CSVDataset, self).__init__() reader = csv.reader(open(file, 'r'), delimiter=',') x = list(reader) self.container = np.array(x).astype('double') and Dataset.py. When I use it from ../dataset like this
from dataset import CSVDataset data = CSVDataset('test/data1') it works only with Dataset.__init__(self). It should work with super(CSVDataset, self).__init__() but it does not. Why is that?
update: I get error
>>> data = CSVDataset('test/data1') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "dataset/CSVDataset.py", line 13, in __init__ super(CSVDataset, self).__init__() TypeError: must be type, not classobj Dataset draft:
class Dataset(Iterable): """ base class representing dataset API. Remember, dataset is used for learning. """ def __init__(self): self.container = None self.counter = None .... class Iterable: def __iter__(self): self.counter = 0 return self def __next__(self): try: label = self[self.counter] self.counter += 1 return label except: raise StopIteration
super()looks correct to me. What error message do you get?class Datasettoo? Presumably this is Python 2?Datasetis an old-style class, not a new-style unified type.