user177215
user177215

Reputation: 249

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

Upvotes: 0

Views: 209

Answers (2)

jldupont
jldupont

Reputation: 96836

The arguments are available through sys.argv.

Upvotes: 1

user177215
user177215

Reputation: 249

Ended up passing the argument to the function that is being called.

Upvotes: 0

Related Questions