On 25 Aug, 22:18, Ross Williamson <rosswilliamson....@gmail.com> wrote: > Is there anyway in a class to overload the print function? > > >> class foo_class(): > >> pass > >> cc = foo_class() > >> print cc > > Gives: > > <__main__.foo_class instance at ....> > > Can I do something like: > > >> class foo_class(): > >> def __print__(self): > >> print "hello" > >> cc = foo_class() > >> print cc > > Gives: > > hello
Yes. Just define the __str__ method, like this: class foo_class(): def __str__(self): return "hello" -- http://mail.python.org/mailman/listinfo/python-list