2023年6月21日 星期三

[Python] Command Line arguments 使用範例

get_input_args.py

import argparse

def get_input_args():

    # Create Parse using ArgumentParser
    parser = argparse.ArgumentParser()

    # Create 3 command line arguments as mentioned above using add_argument() from ArguementParser method
    parser.add_argument('--dir', type = str, default = 'pet_images/', 
                    help = 'path to the folder of pet images') 
    parser.add_argument('--arch', type = str, default = 'vgg',
                        help = 'which CNN Model Architecture')
    parser.add_argument('--dogfile', type = str, default = 'dognames.txt',
                        help = 'Text File with Dog Names')
    
    # Replace None with parser.parse_args() parsed argument collection that 
    # you created with this function 
    return parser.parse_args()


main.py

in_arg = get_input_args()

print(in_arg.dir)

沒有留言:

張貼留言