Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

Am I able to overload the print function and call the normal function from within? 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 don't know how to overload print. I don't know how to do variable length arguments. I'll look it up soon but overload print python just told me I can't overload print in 2.x which is what I am using.

1 Answer

0 votes
by (106k points)

You can use the below-mentioned code for this:

class coder : 

def __init__(self, *coder) : 

self.coder = coder 

def write(self, text) : 

for w in self.coder : 


import sys 

saved = sys.stdout 

fout = file('out.log', 'w') 

sys.stdout = coder(sys.stdout, fout) 

print("Happy coding") 

sys.stdout = saved 


To know more about this you can have a look at the following video tutorial:-


Related questions

0 votes
2 answers
0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
+1 vote
2 answers
0 votes
4 answers
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.6k answers


108k users

Browse Categories