python argparse issues with the help argument (TypeError: %o format: a number is required, not dict)

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

help="about 10%%"
Please follow and like us:
This entry was posted in Python and tagged . Bookmark the permalink.

31 Responses to python argparse issues with the help argument (TypeError: %o format: a number is required, not dict)

  1. Steve H says:

    Thanks!! This was getting me too.

  2. David M says:

    Thanks. I was getting so frustrated with this exact problem!

  3. petrux says:

    Great! Had the very same problem! But how could you manage to have the ‘%’ symbol in the help string?

  4. Patrick says:

    OMG, thank you so much for this post!

  5. lrq3000 says:

    Thank’s a lot!
    Note that the same trick can also fix the following error:
    “TypeError: an integer is required”

  6. Anonymous says:

    Thanks a lot!

  7. Anonymous says:


  8. Jouni K says:

    Thanks a lot!

  9. Anonymous says:


  10. MikeT says:

    Thanks so much for posting this!

  11. Anonymous says:


  12. Anonymous says:

    Thanks! (non-duplicate)

  13. Samuel says:

    Thank you so much for the post!!!

  14. cb says:

    Thanks a lot as well!

    was just googling for this issue and thanks to your posting it was fixed.
    I’m left wondering:
    1: what would happen if people would not write blogs like this.
    (I don’t write a blog whenever I find some solution)
    2: Why is this not yet fixed in latest python? (at least a better error message)

    Anyway thanks again 🙂

  15. Anonymous says:

    Thanks, this solved my problem!

  16. Rolf says:

    You Sir, are a debugging hero. Thanks!

  17. William says:


  18. Sophie says:

    Saved my day, thank you so much!

  19. Douglas A says:


  20. Anonymous says:

    I had the same problem just now and this fixed it.

  21. Natalya says:

    Thank you so much! I spent quite a while trying to figure this out, until I bumped into your post.

  22. Anonymous says:

    heroes don’t all wear capes

  23. CS says:

    Thanks m’dude. That error message is 100%% un-helpful.

  24. Anonymous says:

    You’re such a godsend for making this- much appriciated!!

  25. Anonymous says:

    Thank you for shining a light on what has to be the worst error message ever written.

  26. edo says:

    Yey, you saved my life ty ~<3

  27. edo says:

    Yey, you saved my life ty ~<3

  28. Mitchell says:

    That’s really helpful. THANKS!!!

  29. Anonymous says:


  30. Roman Skielc says:

    Thanks! Solved my problem

Leave a Reply

Your email address will not be published.