我正在使用 argparse 来创建 ipython 魔术。该库在调用时很好地打印了一些文档parser.print_doc()
。但是,有没有办法将文档作为字符串获取,以便我可以将它附加到__doc__
我的 ipython 单元格?
这是我想做的一个例子:
@magics_class
class MagicClass(Magics):
parser = argparse.ArgumentParser(description='Some description.')
parser.add_argument('foo', nargs='*', help='Foo variables.')
[…]
def __init__(self):
# attach the doc from the parser to the __doc__ object of the
# class
self.__doc__.append(parser.get_help_as_string())
[…]