[Tutor] help with __str__

Ron A rha207 at yahoo.com
Wed Sep 1 16:46:14 CEST 2004


In the small program below, I assume that rep is
concantenated when a new object is created
(instantiated?).
If so, it seems that if you put a print statement in
the string method it should be printed out when
an object is created but it's not. I'm a little
confused. Is there somewhere that explains this in a
simple way so even I can understand it?

class Names(object):
        def __init__(self, first, last):
            self.first = first
            self.last = last
            print self.first

        def __str__(self):
            rep = self.first + " " + self.last
            return rep

Ron A


		
_______________________________
Do you Yahoo!?
Win 1 of 4,000 free domain names from Yahoo! Enter now.
http://promotions.yahoo.com/goldrush


More information about the Tutor mailing list