How to get back an overridden python built-in function?

后端 未结 1 598
一向
一向 2020-12-08 14:36

When I was exploring a solution for the StackOverflow problem, Python Use User Defined String Class, I came with this strange python behavior.

def overriden_         


        
相关标签:
1条回答
  • 2020-12-08 15:16

    Just delete the override:

    del print
    

    This deletes the name from the globals() dictionary, letting search fall back to the built-ins.

    You can always refer directly to the built-in via the __builtin__ module as well:

    import __builtin__
    
    __builtin__.print('Printing with the original built-in')
    

    In Python 3, the module has been renamed to builtins.

    0 讨论(0)
提交回复
热议问题