所以我在做一个项目,我必须创建一个类来读取像下面这样的文件中的信息,并把它放到一个列表中。 列表中的每个值都必须分配给一个变量(名称='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
上面的代码返回给我:
[<clients.Clients object at 0x01B77170>, <clients.Clients object at 0x01B77230>, <clients.Clients object at 0x01B77310>]
我不知道为什么。 希望你能帮助我
下面是一个小示例,说明如何使用
__repr__
相关问题 更多 >
编程相关推荐