class CSVFile(object): def __init__(self, filename): self.filename = filename def __iter__(self): return CSVFileIterator(open(self.filename,"r")) class CSVFileIterator(object): def __init__(self, fh): self.fh = fh self.lines = iter(fh.readlines()) def __next__(self): return CSVEntry(next(self.lines)) class CSVEntry(object): def __init__(self,line): self.data = line.split(";") def getInt(self, index): return int(self.data[index]) def getFloat(self, index): return float(self.data[index]) def getString(self, index): return self.data[index] def __getitem__(self, index): return self.getString(index) def __iter__(self): return iter(self.data) def __len__(self): return len(self.data) if __name__ == "__main__": from sys import argv for entry in CSVFile(argv[1]): for field in entry: print("%10s" % field, end="")