<br>Pls help its really frustrating<br>---------- Forwarded message ----------<br>From: Suresh Sharma<br>Date: Monday, December 5, 2011<br>Subject: class print method...<br>To: "<a href="mailto:d@davea.name">d@davea.name</a>" <<a href="mailto:d@davea.name">d@davea.name</a>><br>
<br><br>Dave,<br>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.<br>
<br>Please help<br><br><br><br><br>Suit=[aces,clubs,diamonds,hearts]<br>Rank=[2,3,4,5,6,7,8,9,j,Q,K,A]<br>class Card:<br>Def __init__(self,rannk,suiit):<br>Self.suiit=suiit<br>Self.rannk=rannk<br><br>Def __str__(self):<br>
Return suit[suiit],rank[rannk]<br><br>Class deck:<br>Def __init__(cards):<br>Self.cards=[ ]<br>For suit in range(4):<br>For rank in range(13):<br>Self.cards.append(Card(suit,rank))<br><br>Def __str__(self):<br>s = ""<br>
For card in self.cards:<br>S = str(self.cards)<br>Return s.<br><br><br><br><br><br><br>On Monday, December 5, 2011, Dave Angel <<a href="mailto:d@davea.name">d@davea.name</a>> wrote:<br>> On 12/05/2011 02:11 AM, Suresh Sharma wrote:<br>
>><br>>> Hello All,<br>>> I am new to python and i have stuck up on a particular issue with classes,<br>>> i understand this might be a very dumb question but please help me out.<br>>><br>>> I have created two classes and whenever i try to print the objects i get<br>
>> this message but not the data, __main__.cards instance at ****(memory<br>>> location) i even tried using __str__ but calling it also produces the same<br>>> result. Can anyone please help me how to get my objects printed. I googled<br>
>> a lot but could not find anything relevant.<br>>><br>>> thanks in advance<br>>><br>>> regards<br>>> suresh<br>>><br>> You were close, but you have it backward. You don't call __str__() to print an object, you implement __str__() in your object.<br>
><br>> If you write a class without also writing __str__(), then print won't know what to do with it.<br>><br>> --<br>><br>> DaveA<br>><br>><br><br>--<br>Suresh Sharma<br>Regional Project Manager,<br>
O2F,Mumbai<br>Maharashtra-400101.<br> <br><br><br><br><br><br>-- <br>Suresh Sharma<br>Regional Project Manager,<br>O2F,Mumbai<div>Maharashtra-400101.<br> <br><br></div><br>