acidzombie24 acidzombie24 - 3 months ago 19x
Python Question

overload print python

Am i able to overload the print function? and call the normal function? What i want to do is after a specific line i want print to call my print which will call the normal print and write a copy to file.

Also i dont know how to overload print. I dont know how to do variable length arguments. i'll look it up soon but just told me i cant overload print in 2.x which is what i am using.


Overloading print is a design feature of python 3.0 to address your lack of ability to do so in python 2.x.

However, you can override sys.stdout. (example.) Just assign it to another file-like object that does what you want.

Alternatively, you could just pipe your script through the the unix tee command. python | tee output.txt will print to both stdout and to output.txt, but this will capture all output.