0

So I'm doing a project that I have to create a class that going to read information in a file like the one below, and put it in a list. Each value in the list have to assign to a variable (name = 'Guillaume Dutroux')

Day: 2019-01-12 Time: 09:00 Company: iCageDoree Clients: Guillaume Dutroux, london, 2019-03-12, 13:30, 55, 4*, plumbing, 4h00 Jose Quesada, madrid, 2019-03-12, 10:00, 30, 2*, refrigerators, 5h15 Martin Wyne, london, 2019-04-30, 19:45, 105, 3*, wifi, 0h30

class ReadClients:
def __init__(self, fileClients):
    self._fileClients = fileClients

def readClients(self):
    with open(self._fileClients, "r") as file:
        for i in range(7):
            file.readline()
        self._clientsData = []
        for line in file:
            name, city, date, time, maxValue, minRep, domain, timeWork = line.strip(" ").split(",")
            self._clientsData.append(Clients(name, city, date, time, maxValue, minRep, domain, timeWork))
            self._nameCl = name
            self._cityCl = city
            self._dateCl = date
            self._timeCl = time
            self._maxValueCl = maxValue
            self._minRepCl = minRep
            self._domainCl = domain
            self._timeWorkCl = timeWork
        return self._clientsData

My code above is returning me:

[<clients.Clients object at 0x01B77170>, <clients.Clients object at 0x01B77230>, <clients.Clients object at 0x01B77310>]

and I don't know why. Hope you can Help me.

1 Answers1

1

Here is a small example of how you can play around with __repr__

class my_class:
    def __init__(self,name,age):
        self.name=name
        self.age=age

    def __repr__(self):
        return "(name="+self.name+', '+"age"+str(self.age)+")"

my_list = [my_class('a',1),my_class('a',2)] # [(name=a, age1), (name=a, age2)]
mad_
  • 8,121
  • 2
  • 25
  • 40
  • Thank's, that solves part of the problem, but the other thing is how i'm going to assign the values of the file to the self? – André Ramos Mar 08 '19 at 14:47