Python之获取命令行输入

code:

#!/usr/bin/env python                                                                           
import argparse                                                                                 
                                                                                                
def list():                                                                                     
    """                                                                                         
        get the help info                                                                       
    """                                                                                         
    print("all the help info: info1, info2, info3")                                             
                                                                                                
if __name__ == "__main__":                                                                      
    parse = argparse.ArgumentParser()                                                           
    parse.add_argument('-l', '--list', help='get the help info', action='store_true')           
    parse.add_argument('-a1', '--arg1', default='helloWorld', help='this is the first variable')
                                                                                                
    args = vars(parse.parse_args())                                                             
    if args["list"]:                                                                            
        list()                                                                                  
    if args["arg1"]:                                                                            
        print("arg1 is %s" %(args['arg1']))                                                     
        print("arg1 is %d" %(int(args['arg1'])))                                                

解释略。。。

你可能感兴趣的:(Python,Node)