
import argparse

def main():
    '''
    For help, use argument -h
    $ ./arg-reader.py -h
    To specify an argument, prefix with -
    $ ./arg-reader.py -animalbig hippo -animalsmall fly
    To read arguments from a file, prefix file name with @
    $ ./arg-reader.py @args2.txt
    To specify arguments from command line and from a file
    $ ./arg-reader.py @args.txt -animalbig hippo
    '''

    parser = argparse.ArgumentParser(description='To read arguments from a file, prefix file name with @ e.g. $ ./arg-reader.py @args.txt -animalbig hippo',
                                    fromfile_prefix_chars='@',
                                    )

    parser.add_argument('-animalbig', action="store", dest="animalbig",
                        help = 'name of a big animal')
    parser.add_argument('-animalsmall', action="store", dest="animalsmall",
                        help = 'name of a small animal')

    arguments = parser.parse_args()
    print(arguments)
    print(arguments.animalbig)
    print(arguments.animalsmall)

if __name__ == "__main__": main()



import argparse
from argparse import RawTextHelpFormatter

def main():
    '''
    Read arguments from command line or from a file.
    '''

    parser = argparse.ArgumentParser(description='''    For help, use argument -h
    $ ./arg-reader.py -h
    To specify an argument, prefix with -
    $ ./arg-reader.py -animalbig hippo -animalsmall fly
    To read arguments from a file, prefix file name with @
    $ ./arg-reader.py @args2.txt
    To specify arguments from command line and from a file
    $ ./arg-reader.py @args.txt -animalbig hippo''',
                                    fromfile_prefix_chars='@',
                                    formatter_class=RawTextHelpFormatter,
                                    )

    parser.add_argument('-animalbig', action="store", dest="animalbig",
                        help = 'name of a big animal')
    parser.add_argument('-animalsmall', action="store", dest="animalsmall",
                        help = 'name of a small animal')

    arguments = parser.parse_args()
    print(arguments)
    print(arguments.animalbig)
    print(arguments.animalsmall)

if __name__ == "__main__": main()


Format description to multiple lines using RawTextHelpFormatter.
Format description to multiple lines using RawTextHelpFormatter.

Reference:
# http://stackoverflow.com/questions/3853722/python-argparse-how-to-insert-newline-the-help-text

  
  import argparse
+ from argparse import RawTextHelpFormatter
  
  def main():
      '''
-     For help, use argument -h
+     Read arguments from command line or from a file.
+     '''
+ 
+     parser = argparse.ArgumentParser(description='''    For help, use argument -h
      $ ./arg-reader.py -h
      To specify an argument, prefix with -
      $ ./arg-reader.py -animalbig hippo -animalsmall fly
      To read arguments from a file, prefix file name with @
      $ ./arg-reader.py @args2.txt
      To specify arguments from command line and from a file
-     $ ./arg-reader.py @args.txt -animalbig hippo
+     $ ./arg-reader.py @args.txt -animalbig hippo''',
-     '''
- 
-     parser = argparse.ArgumentParser(description='To read arguments from a file, prefix file name with @ e.g. $ ./arg-reader.py @args.txt -animalbig hippo',
                                      fromfile_prefix_chars='@',
+                                     formatter_class=RawTextHelpFormatter,
                                      )
  
      parser.add_argument('-animalbig', action="store", dest="animalbig",
                          help = 'name of a big animal')
      parser.add_argument('-animalsmall', action="store", dest="animalsmall",
                          help = 'name of a small animal')
  
      arguments = parser.parse_args()
      print(arguments)
      print(arguments.animalbig)
      print(arguments.animalsmall)
  
  if __name__ == "__main__": main()
  
  
Format description to multiple lines using RawTextHelpFormatter.
## Code Before:

import argparse

def main():
    '''
    For help, use argument -h
    $ ./arg-reader.py -h
    To specify an argument, prefix with -
    $ ./arg-reader.py -animalbig hippo -animalsmall fly
    To read arguments from a file, prefix file name with @
    $ ./arg-reader.py @args2.txt
    To specify arguments from command line and from a file
    $ ./arg-reader.py @args.txt -animalbig hippo
    '''

    parser = argparse.ArgumentParser(description='To read arguments from a file, prefix file name with @ e.g. $ ./arg-reader.py @args.txt -animalbig hippo',
                                    fromfile_prefix_chars='@',
                                    )

    parser.add_argument('-animalbig', action="store", dest="animalbig",
                        help = 'name of a big animal')
    parser.add_argument('-animalsmall', action="store", dest="animalsmall",
                        help = 'name of a small animal')

    arguments = parser.parse_args()
    print(arguments)
    print(arguments.animalbig)
    print(arguments.animalsmall)

if __name__ == "__main__": main()


## Instruction:
Format description to multiple lines using RawTextHelpFormatter.
## Code After:

import argparse
from argparse import RawTextHelpFormatter

def main():
    '''
    Read arguments from command line or from a file.
    '''

    parser = argparse.ArgumentParser(description='''    For help, use argument -h
    $ ./arg-reader.py -h
    To specify an argument, prefix with -
    $ ./arg-reader.py -animalbig hippo -animalsmall fly
    To read arguments from a file, prefix file name with @
    $ ./arg-reader.py @args2.txt
    To specify arguments from command line and from a file
    $ ./arg-reader.py @args.txt -animalbig hippo''',
                                    fromfile_prefix_chars='@',
                                    formatter_class=RawTextHelpFormatter,
                                    )

    parser.add_argument('-animalbig', action="store", dest="animalbig",
                        help = 'name of a big animal')
    parser.add_argument('-animalsmall', action="store", dest="animalsmall",
                        help = 'name of a small animal')

    arguments = parser.parse_args()
    print(arguments)
    print(arguments.animalbig)
    print(arguments.animalsmall)

if __name__ == "__main__": main()

