0

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())
        […]
cphyc
  • 440
  • 5
  • 16

1 Answers1

1

I think you're looking for the format_help() method.

Alasdair
  • 298,606
  • 55
  • 578
  • 516