Re: Overload print

2010-08-27 Thread genxtech
On Aug 25, 5:18 pm, Ross Williamson wrote: > Hi All > > 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()

Re: Overload print

2010-08-26 Thread John Roth
On Aug 25, 3:42 pm, Alexander Kapps wrote: > Ross Williamson wrote: > > Hi All > > > Is there anyway in a class to overload the print function? > > In Python <= 2.x "print" is a statement and thus can't be > "overloaded". That's exactly the reason, why Python 3 has turned > "print" into a function

Re: Overload print

2010-08-25 Thread Chris Kaynor
On Wed, Aug 25, 2010 at 2:23 PM, Glenn Hutchings wrote: > On 25 Aug, 22:18, Ross Williamson > 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 in

Re: Overload print

2010-08-25 Thread Alexander Kapps
Ross Williamson wrote: Hi All Is there anyway in a class to overload the print function? In Python <= 2.x "print" is a statement and thus can't be "overloaded". That's exactly the reason, why Python 3 has turned "print" into a function. class foo_class(): def __print__(self):

Re: Overload print

2010-08-25 Thread D'Arcy J.M. Cain
On Wed, 25 Aug 2010 16:18:15 -0500 Ross Williamson wrote: > Hi All > > Is there anyway in a class to overload the print function? Your terminology threw me off for a moment. You don't want to override print. You want to override the default representation of an object. > > >> class foo_class

Re: Overload print

2010-08-25 Thread Chris Rebert
On Wed, Aug 25, 2010 at 2:18 PM, Ross Williamson wrote: > Hi All > > 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 f

Re: Overload print

2010-08-25 Thread Glenn Hutchings
On 25 Aug, 22:18, Ross Williamson 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(): > >>     de