You could write __str__ function<div><br></div><div><div><div>&gt;&gt;&gt; class card(object):</div><div>...     def __init__(self, card1, card2):</div><div>...             self.card1, self.card2 = card1, card2</div><div>...     def __str__(self):</div>

<div>...             return str(str(self.card1)+&#39;,&#39;+str(self.card2))</div><div>...</div><div>&gt;&gt;&gt; a = card(0,0)</div><div>&gt;&gt;&gt; str(a)</div><div>&#39;0,0&#39;</div></div><br><div class="gmail_quote">

On Wed, Aug 4, 2010 at 10:37 AM, Alex Hall <span dir="ltr">&lt;<a href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi all,<br>
I have a card class. A card object simply consists of a pair of<br>
numbers; 0,0 might be the ace of clubs, for example. I have a toString<br>
method in my card class. Is there a way to just say str(card) instead<br>
of card.toString()? Maybe some sort of basic, built-in function to<br>
override? TIA. Oh, what about doing the same with operators? For<br>
example, could I get the program to call my own math functions when it<br>
sees a card object in a math expression, like<br>
if(card1==card2)<br>
<font color="#888888"><br>
--<br>
Have a great day,<br>
Alex (msg sent from GMail website)<br>
<a href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</a>; <a href="http://www.facebook.com/mehgcap" target="_blank">http://www.facebook.com/mehgcap</a><br>
_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</font></blockquote></div><br></div>