0

Please find below the code i wrote (based on the assignment) and the error message i got back. I m new to python so i apologize in advance if this is super obvious.

   def get_input_args():

    """
    Retrieves and parses the 3 command line arguments provided by the user when
    they run the program from a terminal window. This function uses Python's
    argparse module to created and defined these 3 command line arguments. If
    the user fails to provide some or all of the 3 arguments, then the default
    values are used for the missing arguments.
    Command Line Arguments:
    1. Image Folder as --dir with default value 'pet_images'
    2. CNN Model Architecture as --arch with default value 'vgg'
    3. Text File with Dog Names as --dogfile with default value 'dognames.txt'
    This function returns these arguments as an ArgumentParser object.
    Parameters:
    None - simply using argparse module to create & store command line arguments
    Returns:
    parse_args() -data structure that stores the command line arguments object
    """

    parser = argparse.ArgumentParser()

    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 = 'CNN model Architecture VGG')

    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**

    args = parser.parse_args('--dir', '--arch', '--dogfile')



root@791d23aa2615:/home/workspace# python check_images.py
Traceback (most recent call last):
File "check_images.py", line 131, in <module>
main()
File "check_images.py", line 51, in main
in_arg = get_input_args()
File "/home/workspace/get_input_args.py", line 49, in get_input_args
args = parser.parse_args('--dir', '--arch', '--dogfile')
TypeError: parse_args() takes from 1 to 3 positional arguments but 4 were given

thank you

After Charles answer I used

args = parser.parse_args()

But I cannot get the default values as I should

* Doesn't Check the Command Line Arguments because 'get_input_args' hasn't been defined.
* Doesn't Check the Results Dictionary because 'get_pet_labels' hasn't been defined.
* Doesn't Check the Results Dictionary because 'classify_images' hasn't been defined.
* Doesn't Check the Results Dictionary because 'adjust_results4_isadog' hasn't been defined.
* Doesn't Check the Results Dictionary because 'calculates_results_stats' hasn't been defined.

** Total Elapsed Runtime: 0:0:10

2 Answers 2

1

parse_args is indicated as the problem in your traceback, and the way you call that method is contrary to how they describe it in the docs. parse_args() takes the args by default from the command line so try just calling it args = parser.parse_args()

Otherwise if you wanted to do it manually you could do something like: parser.parse_args(['--foo', 'FOO'])

The docs: https://docs.python.org/3/library/argparse.html#argparse.ArgumentParser.parse_args

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Charles
when i run args = parser.parse_args() I don't get the default values as I m supposed to get. I get this instead : * Doesn't Check the Command Line Arguments because 'get_input_args' hasn't been defined. * Doesn't Check the Results Dictionary because 'get_pet_labels' hasn't been defined. * Doesn't Check the Results Dictionary because 'classify_images' hasn't been defined. * Doesn't Check the Results Dictionary because 'adjust_results4_isadog' hasn't been defined. * Doesn't Check the Results Dictionary because 'calculates_results_stats' hasn't been defined. ** Total Elapsed Runtime: 0:0:1
That's not a traceback...is this a homework assignment? If your homework system sent you that then we can't know how to fix that... it seems to say that you are required to define functions with each of those names
0

Thank you fro your help everybody

I found the answer that yields the defaults command lines

return parser.parse_args()

with the hint of Charles and some more help I finally found it

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.