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).
1 2 3 4 5 |
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
1 |
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
1 |
help="about 10%%" |
Thanks!! This was getting me too.
Thanks. I was getting so frustrated with this exact problem!
Great! Had the very same problem! But how could you manage to have the ‘%’ symbol in the help string?
OMG, thank you so much for this post!
Thank’s a lot!
Note that the same trick can also fix the following error:
“TypeError: an integer is required”
Thanks a lot!
Thanks!
Thanks!
Thanks a lot!
THANKS
Thanks so much for posting this!
Thanks!!!
Thanks! (non-duplicate)
Thank you so much for the post!!!
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 🙂
Thanks, this solved my problem!
You Sir, are a debugging hero. Thanks!
Awesome!
Saved my day, thank you so much!
THANKS!
I had the same problem just now and this fixed it.
Thank you so much! I spent quite a while trying to figure this out, until I bumped into your post.
heroes don’t all wear capes
Thanks m’dude. That error message is 100%% un-helpful.