如果您将help(object)别名为您注释的某个函数(与inspect.getsource(k)相同),则内置的help(object)将为您提供正确的文档,此时它们知道哪个函数是由您的变量名aliask命名的。在
参见:
示例:# reusing this code - created it for some other question today
class well_documented_example_class(object):
"""Totally well documented class"""
def parse(self, message):
"""This method does coool things with your 'message'
'message' : a string with text in it to be parsed"""
self.data = [x.strip() for x in message.split(' ')]
return self.data
# alias for `parse()`:
k = well_documented_example_class.parse
help(k)
印刷品:
^{pr2}$
^{}也一样:# from https://stackoverflow.com/a/52333691/7505395
import inspect
print(inspect.getsource(k))
印刷品:def parse(self, message):
"""This method does coool things with your 'message'
'message' : a string with text in it to be parsed"""
self.data = [x.strip() for x in message.split(' ')]
return self.data