Is there class like that in Python3?

Hello. I am python newbie, just learning. I have written this class, when I realized, that maybe there is some class built-in?

class Data:
    def __init__(self):
        self.table = []        
        self.iterator = iter(self.table)
        self.current_index = 0
        self.valid_bus_stop_counter = 0

    def reset_iterator(self):
            self.iterator = iter(self.table)
    def fill(self, reader):
        for row in reader:
            self.table.append(row)
    def __iter__(self):
        self.index = 0
        return self
    def next(self):
        if self.iterator is None:
            raise StopIteration
        try:
            result = next(self.iterator)
            return result
        except StopIteration:
            self.iterator = None
            raise StopIteration
    def set_index(self, current_index):
        self.current_index = current_index
    def inc(self):
        self.current_index += 1
    def countStop(self):
        self.valid_bus_stop_counter += 1
    def get_index(self):
        return self.current_index

And if there is such class that I can use to store array and pointer to current row (in a for loop I usually called it i like for i,row in table) or iterator to be saved. But I would like to add my own methods to it or even members like .bus_stops , .bus_stops_counter and similar...

I use it like that:

            data = Data()
            differencesBetweenBusStops = Data()
            with open(csv_file, 'r', encoding='utf-8') as f:
                reader = csv.reader(f, delimiter='\t')
                first_row = next(reader)
                idt = first_row[1]
                next(reader)                                 
                data.fill(reader) 
                reset()
                for i, row in enumerate(data.table):
                     ... find out and collect bus stops names
                     ... and collect differences (distances) between bus stops.

when you say 'saved' is that between invocations of the program or during a single run ?

if between invocations - check out python pickling may be what you're after , if not, please elaborate.
pickle

Single run, no data streaming. In my program I have one object data, one object reader of csv file and maybe yet one or two objects. Instead of storing like 16 globals or arrays and integers, I prefered to have only 2 globals, and data passed through objects into functions. So the objects replaced arrays and global help variables. But I would like to know if I should stay with this Class Data as my definition or to use some general class, which I could extend with my specific members or methods.

@visitor123 , offhand no particular class / module comes to mind (though I'm not regularly massaging python code) , plus, your effort looks reasonable and concise, so if the shoe fits ... wear it. having rolled your own also facilitates easy extension etc.

happy coding.

Hi @visitor123,

the class def seems a little oversized to me. It would be helpful if you could post a snippet of your CSV and explain in a little more detail how you want to process the data.

It was a hard objective to grasp. I gave up. I choosed different source of data to import.