Even though Python has a great documentation, once in a while you get stuck on a single problem more than expected.
It happenned to me today with the argparse module, which I thought I knew enough to quickly code a user interface application.
Here is an example of what I was trying to do (in a more complex code but we will get the idea).
import argparse parser = argparse.ArgumentParser() parser.add_argument('--elitism', type=int, default=5, dest="elitism", help='should be an integer less than popsize. Ideally, about 10%') args = parser.parse_args()
I got, this kind of error
TypeError: %o format: a number is required, not dict
and the reason is that in the help string there is a % sign, which is not recognised!!!! As simple as that…. The error message being misleading and the code used was embedded in more complex code, so this was not easy to track done… a bit frustrating
And the solution is to double the percent character