Python Option Parser: Boolean flag with optional parameters -


i'm using optparse.optionparser manage arguments scripts, , wondering / have boolean flags (i.e action=store_true) can accept parameter.

to put context, i've got application can use many gpu/processors finds on machine. variety of reasons want limit number of devices uses, , instead of further cluttering command line, i'd able to:

script -c -g 

meaning use can of cpus , gpus, ,

script -c 2 -g 3 

meaning limit script execution 2 cpus , 3 gpus.

after reading optparse documentation, i'm none wiser. oh great gurus! lend me wisdom!

you can use callback action implement quite easily. in particular, example 6 in documentation of callback action of optionparser discusses variable number of arguments. here's telling quote example:

things hairy when want option take variable number of arguments. case, must write callback, optparse doesn’t provide built-in capabilities it.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -