a newbie OptParse thread. Is there a way to catch all?

G

googleboy

Hiya everyone.

I have now implemented my newbie script with optparse and it works
great, but in the final QA phase I found that I could put any sort of
stuff on the command line anywhere and the script would simply ignore
it, rather than breaking with an error. IE, after I define -h, -V,
-s, -t, -w, -c and their relevent lnog versions as valid parameters,
I call the program thus:

$>./my_script -s 3 -c 88 asdsa -w99 -t14
OK. The script worked great!


Is there some way of implementing a catchall type of add_option that
would run a callback to some sort of predefined error function?
Something that could catch that "asdsa" stuff?

Or is there a better way (more pythonish!) to do it?

Thanks for your attention!

googleboy
 
J

Jeff Epler

Just check that 'args' is empty in the return from
(options, args) = parser.parse_args()
"asdsa" would be in args, because it's not recognized as a part of any
option.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBAA9MJd01MZaTXX0RAgn5AJ9SMzu4NFhkYpvLF6bgHVdMuFDDawCeI7dg
F50lz5uVSJtFcrfTg7TO1II=
=uEIA
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,664
Latest member
RoseannBow

Latest Threads

Top