为了账号安全,请及时绑定邮箱和手机立即绑定

要列出的 Python 类文件

要列出的 Python 类文件

Qyouu 2021-11-30 16:16:55
所以我正在做一个项目,我必须创建一个类,该类将读取如下文件中的信息,并将其放入列表中。列表中的每个值都必须分配给一个变量(名称 = 'Guillaume Dutroux')日期:2019-01-12 时间:09:00 公司:iCageDoree 客户:Guillaume Dutroux,伦敦,2019-03-12,13:30,55,4*,管道,4h00 Jose Quesada,马德里,2019-03-12 , 10:00, 30, 2*, 冰箱, 5h15 Martin Wyne, 伦敦, 2019-04-30, 19:45, 105, 3*, wifi, 0h30class ReadClients:def __init__(self, fileClients):    self._fileClients = fileClientsdef 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>]我不知道为什么。希望您能够帮助我。
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

这是一个关于如何玩的小例子 __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)]


查看完整回答
反对 回复 2021-11-30
  • 1 回答
  • 0 关注
  • 120 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信