Python使类函数打印它所调用的函数的docstring。

问题描述 投票:0回答:1

有没有一种简单的方法可以让类方法在返回我在不同模块中写的函数的docstring时 help(my_classfunction) 被调用时,有什么办法让类方法返回我在不同模块中写的函数的docstring?

python oop docstring
1个回答
0
投票

深入研究了一下,我发现了以下方法 此相关问题 解决了我的问题。结果我不得不用 __func__ 当设置类方法的 docstring 时,将类方法的 docstring 设置为其调用的函数的 docstring。self.my_classmethod.__func__.__doc__ = my_module.my_function.__doc__ 将类方法的 docstring 设置为其调用的函数的 docstring。

© www.soinside.com 2019 - 2024. All rights reserved.