Search code examples
pythonironpythonoptparse

Optparse library - callback action while storing arg


My code:

def main():
    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    parser.add_option("-p", "--pending", action="callback", callback=pending, type="string", dest="test", help="View Pending Jobs")
    (options, args) = parser.parse_args()
    if x == 0:
        print usage, " (-h or --help for help)"
    print options.test

if i had: script -p hello

i need options.test to print out the argument as type string


Solution

  • The arguments are available through sys.argv.