I am using argparse to create an ipython magic. The library is nicely printing some documentation when calling parser.print_doc()
. However, is there a way to get the documentation as a string instead, so that I can attach it to __doc__
of my ipython cell?
Here is an example of what I want to do:
@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())
[…]