Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I call a built-in function, if the function is already overrided in Python3

Now I just tried to test if I can call built-in function inside overrided function in Python3, as follows:

def print(val=0):
    print("TEST")  # How can I call the original `print()` here to avoid RecursionError


print(10)

But the following error thrown. It makes sense.

>>> RecursionError: maximum recursion depth exceeded

I am curious if there is ways to call an original built-in function inside its overrided function, such as sys.__builtin__.print() I guess.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you.

>Solution :

Builtins are available in a module called builtins. Makes sense!

import builtins

def print(val=0):
    builtins.print("TEST")  # How can I call the original `print()` here to avoid RecursionError

print(10)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading