On Thu, Nov 12, 2009 at 5:31 AM, Modulok <modu...@gmail.com> wrote:
> List,
>
> How do I get a print statement to call a class method? I'm using
> python 2.5. I did it long ago, but can't remember how, or even where I
> learned it from. Something like:
>
> class Foo():
>   def __init__(self):
>      pass
>
>   def  ***part I can't remember goes here***
>      print "hello world!"

You want the __str__() special method. Note that it returns a string,
it doesn't itself print:
def __str__(self):
  return "hello world"

Kent
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to