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).

I got, this kind of error

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

This entry was posted in Python and tagged . Bookmark the permalink.

15 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:

    Thanks!

  8. Jouni K says:

    Thanks a lot!

  9. Anonymous says:

    THANKS

  10. MikeT says:

    Thanks so much for posting this!

  11. Anonymous says:

    Thanks!!!

  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 🙂

Leave a Reply

Your email address will not be published.