Program along with all the switches, runs great, but argparse '--help' throws a lot of errors
Question: I am using argparse in Python to handle arguments in my program. For instance,
as seen below, if I use the argument '-p' a specific module is execute. Now,
all arguments and the program runs great. But when I try to get the '--help'
for my program it crashes horribly (image).

Here is the code pertaining to argparse:

    
    
    parser = argparse.ArgumentParser(description="something1.")
    parser.add_argument('-x', '--xoo', help='something2', action='store_true')
    parser.add_argument('-a', '--al', help='something3', action='store_true')
    parser.add_argument('-c', '--conv', help='something4', type=float)
    parser.add_argument('-p', '--pay', help='something5', type=float)
    args = parser.parse_args()
    

Any ideas as to how I can correct this error??

    
    
    $ ./xoom.py -h
    Traceback (most recent call last):
      File "./xoom.py", line 46, in <module>
        args = parser.parse_args()
      File "/usr/lib/python2.7/argparse.py", line 1688, in parse_args
        args, argv = self.parse_known_args(args, namespace)
      File "/usr/lib/python2.7/argparse.py", line 1723, in parse_known_args
        namespace, args = self._parse_known_args(args, namespace)
      File "/usr/lib/python2.7/argparse.py", line 1929, in _parse_known_args
        start_index = consume_optional(start_index)
      File "/usr/lib/python2.7/argparse.py", line 1869, in consume_optional
        take_action(action, args, option_string)
      File "/usr/lib/python2.7/argparse.py", line 1797, in take_action
        action(self, namespace, argument_values, option_string)
      File "/usr/lib/python2.7/argparse.py", line 994, in __call__
        parser.print_help()
      File "/usr/lib/python2.7/argparse.py", line 2319, in print_help
        self._print_message(self.format_help(), file)
      File "/usr/lib/python2.7/argparse.py", line 2293, in format_help
        return formatter.format_help()
      File "/usr/lib/python2.7/argparse.py", line 279, in format_help
        help = self._root_section.format_help()
      File "/usr/lib/python2.7/argparse.py", line 209, in format_help
        func(*args)
      File "/usr/lib/python2.7/argparse.py", line 209, in format_help
        func(*args)
      File "/usr/lib/python2.7/argparse.py", line 515, in _format_action
        help_text = self._expand_help(action)
      File "/usr/lib/python2.7/argparse.py", line 601, in _expand_help
        return self._get_help_string(action) % params
    TypeError: float argument required, not dict
    


Answer: The problem is that you have % characters in your `something4` and/or
`something5`.

Remove them and see if you still get the error.

If you really need % characters in those help texts, try replacing them with
%% - i.e. use two percent characters in a row.

Update: Here is a minimal example which demonstrates why you are getting the
error:

    
    
    import argparse
    
    parser = argparse.ArgumentParser(description="something1.")
    parser.add_argument('-c', '--conv', help='somet%fhing4', type=float)
    args = parser.parse_args()
    

Run with `--help` to generate the error message. Note the % character in the
help string.

