0

我正在使用 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())
        […]
4

1 回答 1

1

我想你正在寻找format_help()方法。

于 2016-05-18T08:59:03.093 回答