Unable to resolve "Learn Python on AWS Workshop Python" error involving looping over JSON

0

I haven't been able to resolve the the following error that keeps showing up at the end of the Looping over JSON portion of Lab 6 in the "Learn Python on AWS Workshop" module:

error: the following arguments are required_ --file

Following the directions throughout the lab, I created the JSON file called translate_input.json and copied the list of dictionaries contained within. Then I created a new python file called lab_6_step_2_loops.py , typed in the text as directed, and ran the program with the command in the terminal python lab_6_step_2_loops.py --file translate_input.json after which the above error appears.

I reached out to some coworkers who were also working on this but none of them have gotten back to me yet. Additionally, I've gone over all of the previous labs of this Python workshop to see what/if I missed anything, read numerous explanations, and watched several tutorials on YouTube regarding argparse and json. All of this was helpful but danced around the general issue without actually helping me resolve it but leads me to think the issue is related to the first section of the code.

parser = argparse.ArgumentParser(description="Provides translation  between one source language and another of the same set of languages.")
parser.add_argument(
    '--file',
    dest='filename',
    help="The path to the input file. The file should be valid json",
    required=True)

Leaving this code as is, inputting the file name, file path, destination, or some combination keeps bringing up the same error as above. When I follow the directions in the link and literally just copy and paste- no typing- the text, I still come up with this error. Any thoughts?

1 Answer
0

Based on the error, it looks like you may be executing the python file without the --file argument. Make sure you include --file translate_input.json like this:

python lab_6_step_2_loops.py --file translate_input.json
profile pictureAWS
EXPERT
Chris_G
answered 2 years ago
  • Thank you! How exactly would that look like in the code? I know I've tried this without success, and again just now after you suggested it, but I may also be misunderstanding or thinking of something completely different.

  • This would not be in the code, this is what you would execute in the command line after pasting the code into lab_6_step_2_loops.py.

  • Thanks for clarifying. I've done that more times than I can remember so I'm ready to admit the error is something out of my control. Thank you for your help!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions