<i id='6NNf9'><tr id='6NNf9'><dt id='6NNf9'><q id='6NNf9'><span id='6NNf9'><b id='6NNf9'><form id='6NNf9'><ins id='6NNf9'></ins><ul id='6NNf9'></ul><sub id='6NNf9'></sub></form><legend id='6NNf9'></legend><bdo id='6NNf9'><pre id='6NNf9'><center id='6NNf9'></center></pre></bdo></b><th id='6NNf9'></th></span></q></dt></tr></i><div id='6NNf9'><tfoot id='6NNf9'></tfoot><dl id='6NNf9'><fieldset id='6NNf9'></fieldset></dl></div>

        <small id='6NNf9'></small><noframes id='6NNf9'>

        <legend id='6NNf9'><style id='6NNf9'><dir id='6NNf9'><q id='6NNf9'></q></dir></style></legend>
        <tfoot id='6NNf9'></tfoot>
        • <bdo id='6NNf9'></bdo><ul id='6NNf9'></ul>
      1. 如何在 Python 中对函数进行深度复制?

        时间:2023-08-31

              <tbody id='Fmxx7'></tbody>

              • <bdo id='Fmxx7'></bdo><ul id='Fmxx7'></ul>
                <tfoot id='Fmxx7'></tfoot>

                <legend id='Fmxx7'><style id='Fmxx7'><dir id='Fmxx7'><q id='Fmxx7'></q></dir></style></legend>
              • <small id='Fmxx7'></small><noframes id='Fmxx7'>

                <i id='Fmxx7'><tr id='Fmxx7'><dt id='Fmxx7'><q id='Fmxx7'><span id='Fmxx7'><b id='Fmxx7'><form id='Fmxx7'><ins id='Fmxx7'></ins><ul id='Fmxx7'></ul><sub id='Fmxx7'></sub></form><legend id='Fmxx7'></legend><bdo id='Fmxx7'><pre id='Fmxx7'><center id='Fmxx7'></center></pre></bdo></b><th id='Fmxx7'></th></span></q></dt></tr></i><div id='Fmxx7'><tfoot id='Fmxx7'></tfoot><dl id='Fmxx7'><fieldset id='Fmxx7'></fieldset></dl></div>

                  本文介绍了如何在 Python 中对函数进行深度复制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 Python 中制作一个函数的深拷贝.copy 模块没有帮助,根据 documentation,其中说:

                  I would like to make a deepcopy of a function in Python. The copy module is not helpful, according to the documentation, which says:

                  此模块不会复制模块、方法、堆栈跟踪、堆栈帧、文件等类型,套接字、窗口、数组或任何类似类型.它会复制"函数和类(浅和深度),通过返回原始对象不变;这与方式兼容这些由 pickle 模块处理.

                  This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does "copy" functions and classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the pickle module.

                  我的目标是拥有两个具有相同实现但具有不同文档字符串的函数.

                  My goal is to have two functions with the same implementation but with different docstrings.

                  def A():
                      """A"""
                      pass
                  
                  B = make_a_deepcopy_of(A)
                  B.__doc__ = """B"""
                  

                  那么如何做到这一点呢?

                  So how can this be done?

                  推荐答案

                  FunctionType 构造函数用于对函数进行深拷贝.

                  The FunctionType constructor is used to make a deep copy of a function.

                  import types
                  def copy_func(f, name=None):
                      return types.FunctionType(f.func_code, f.func_globals, name or f.func_name,
                          f.func_defaults, f.func_closure)
                  
                  def A():
                      """A"""
                      pass
                  B = copy_func(A, "B")
                  B.__doc__ = """B"""
                  

                  这篇关于如何在 Python 中对函数进行深度复制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:切片操作会给我一个深拷贝还是浅拷贝? 下一篇:在 Python 中复制多个文件

                  相关文章

                • <i id='d3UGU'><tr id='d3UGU'><dt id='d3UGU'><q id='d3UGU'><span id='d3UGU'><b id='d3UGU'><form id='d3UGU'><ins id='d3UGU'></ins><ul id='d3UGU'></ul><sub id='d3UGU'></sub></form><legend id='d3UGU'></legend><bdo id='d3UGU'><pre id='d3UGU'><center id='d3UGU'></center></pre></bdo></b><th id='d3UGU'></th></span></q></dt></tr></i><div id='d3UGU'><tfoot id='d3UGU'></tfoot><dl id='d3UGU'><fieldset id='d3UGU'></fieldset></dl></div>

                    <tfoot id='d3UGU'></tfoot>

                    <small id='d3UGU'></small><noframes id='d3UGU'>

                        <bdo id='d3UGU'></bdo><ul id='d3UGU'></ul>

                    1. <legend id='d3UGU'><style id='d3UGU'><dir id='d3UGU'><q id='d3UGU'></q></dir></style></legend>