Overload print

R

Ross Williamson

Hi All

Is there anyway in a class to overload the print function?

Gives:

<__main__.foo_class instance at ....>

Can I do something like:

Gives:

hello

I'm looking at finding nice way to print variables in a class just by
asking to print it

Cheers

Ross


--
Ross Williamson
University of Chicago
Department of Astronomy & Astrophysics
773-834-9785 (office)
312-504-3051 (Cell)
 
G

genxtech

Hi All

Is there anyway in a class to overload the print function?


Gives:

<__main__.foo_class instance at ....>

Can I do something like:


Gives:

hello

I'm looking at finding nice way to print variables in a class just by
asking to print it

Cheers

Ross

--
Ross Williamson
University of Chicago
Department of Astronomy & Astrophysics
773-834-9785 (office)
312-504-3051 (Cell)

Are you talking about overriding print(), kind of like overloading the
<< operator in c++ so that you can determine how the foo_class gets
printed?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top