Pls help its really frustrating ---------- Forwarded message ---------- From: Suresh Sharma Date: Monday, December 5, 2011 Subject: class print method... To: "d...@davea.name" <d...@davea.name>
Dave, Thanx for the quick response, i am sorry that i did not explain correctly look at the code below inspite of this i am just getting class object at memory location.I am sort i typed all this code on my android in a hurry so.indentation could.not.be.managed but this.similar code when i run all my objects created by class deck are not shown but stored in varioia meory locations. How can i display them. Please help Suit=[aces,clubs,diamonds,hearts] Rank=[2,3,4,5,6,7,8,9,j,Q,K,A] class Card: Def __init__(self,rannk,suiit): Self.suiit=suiit Self.rannk=rannk Def __str__(self): Return suit[suiit],rank[rannk] Class deck: Def __init__(cards): Self.cards=[ ] For suit in range(4): For rank in range(13): Self.cards.append(Card(suit,rank)) Def __str__(self): s = "" For card in self.cards: S = str(self.cards) Return s. On Monday, December 5, 2011, Dave Angel <d...@davea.name> wrote: > On 12/05/2011 02:11 AM, Suresh Sharma wrote: >> >> Hello All, >> I am new to python and i have stuck up on a particular issue with classes, >> i understand this might be a very dumb question but please help me out. >> >> I have created two classes and whenever i try to print the objects i get >> this message but not the data, __main__.cards instance at ****(memory >> location) i even tried using __str__ but calling it also produces the same >> result. Can anyone please help me how to get my objects printed. I googled >> a lot but could not find anything relevant. >> >> thanks in advance >> >> regards >> suresh >> > You were close, but you have it backward. You don't call __str__() to print an object, you implement __str__() in your object. > > If you write a class without also writing __str__(), then print won't know what to do with it. > > -- > > DaveA > > -- Suresh Sharma Regional Project Manager, O2F,Mumbai Maharashtra-400101. -- Suresh Sharma Regional Project Manager, O2F,Mumbai Maharashtra-400101.
-- http://mail.python.org/mailman/listinfo/python-list