how to(can we ?) pass argument to .py script ?

billie mlist at fastwebnet.it
Wed Oct 12 05:42:40 EDT 2005


It's quite simple. If this usage example can helps you...

### parser
try:
    opts, args = getopt.getopt(sys.argv[1:], "h, e, p:", ["help"])
    mode = 'reply' # default mode
    pwd = ' ' # default pass (blank)
    for o, a in opts:
        if o == '--help' or o == '-h':
            print helper()
            os._exit(0)
        if o == '-h':
            print helper()
            os._exit(0)
        if o == '-e':
            mode = 'echo/reply'
        if o == '-p':
            pwd = a
    if len(args) < 3 :
        print " ERR: Too much few arguments.\n Type %s -h for help." \
        %(sys.argv[0])
        os._exit(0)
    if len(args) > 3:
        print \
" ERR: Too much arguments.\n Type -h and \
look example to send argumented commands."
        os._exit(0)
except:
    print " ERR: Invalid Option.\n Type %s -h for help." \
    %(sys.argv[0])
    os._exit(0)
### /parser 





More information about the Python-list mailing list