Does an equivalent of override exist for nested functions?

后端 未结 2 1041
渐次进展
渐次进展 2021-01-02 18:56

If I have this function, what should I do to replace the inner function with my own custom version?

def foo():
    def bar():
        # I want to change this         


        
2条回答
  •  情书的邮戳
    2021-01-02 19:26

    You can pass it in as an optional parameter

    def foo(bar=None):
        def _bar():
            # I want to change this
            pass
        if bar is None:
            bar = _bar
    

提交回复
热议问题