How to create new closure cell objects?

前端 未结 3 1129
迷失自我
迷失自我 2021-01-15 01:41

I need to monkey-patch my library to replace an instance of a symbol, and it\'s getting referenced by some function closures. I need to copy those functions (since I also ne

3条回答
  •  忘掉有多难
    2021-01-15 02:24

    in lambda:

    def make_cell(value):
        fn = (lambda x: lambda: x)(value)
        return fn.__closure__[0]
    

    got anwer from https://github.com/nedbat/byterun/blob/master/byterun/pyobj.py#L12

提交回复
热议问题