I cannot display object lists - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I cannot display object lists (/thread-18143.html) |
I cannot display object lists - Karaca - May-07-2019 Hİ when I try to view the staff list. eror:<<<<<< <__main__.Çalışan object at 0x0000000002D92550> <<<<<< def personele_ekle(): isim = raw_input() yeniobj = Çalışan(isim) Çalışan.personel.append(yeniobj) print yeniobj.isim print('{} adlı kişi personele eklendi'.format(yeniobj.isim)) class Çalışan(): personel = [] def __init__(self, isim): self.isim = isim self.kabiliyetleri = [] @classmethod def personel_sayısını_görüntüle(cls): print(len(cls.personel)) @classmethod def personeli_görüntüle(cls): print('Personel listesi:') for kişi in cls.personel: print(kişi) def kabiliyet_ekle(self, kabiliyet): self.kabiliyetleri.append(kabiliyet) def kabiliyetleri_görüntüle(self): print('{} adlı kişinin kabiliyetleri:'.format(self.isim)) for kabiliyet in self.kabiliyetleri: print(kabiliyet) def personele_ekle(): isim = raw_input() yeniobj = Çalışan(isim) Çalışan.personel.append(yeniobj) print yeniobj.isim print('{} adlı kişi personele eklendi'.format(yeniobj.isim)) personele_ekle() Çalışan.personel_sayısını_görüntüle() Çalışan.personeli_görüntüle() RE: I cannot display object lists - buran - May-07-2019 (May-07-2019, 08:13 AM)Karaca Wrote: eror:<<<<<< <__main__.Çalışan object at 0x0000000002D92550> <<<<<<That's not an error. That is general representation of instance of your class. You need to implement __str__() method for your class if you want "nice" print. There is also __repr__ method (it's a bit different). Here you can read more https://docs.python.org/3/reference/datamodel.html#object.__str__ by the way, I am confused by Turkish language, but I don't see where you print the instance itself. I see you printing just some attributes of the instance. so this output is not result of exactly this code. RE: I cannot display object lists - Karaca - May-07-2019 Thank you for your interest... |