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()
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
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
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):
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
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
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