350-401 · Question #677
350-401 Question #677: Real Exam Question with Answer & Explanation
The correct answer is C: Append to the body of the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response.text). Option C is correct because the file-writing block must be appended inside (as part of the body of) the for loop so that a separate JSON file is created for each device using that device's hostname. Response.text already contains the raw JSON-formatted string returned by the HTTP
Question
Refer to the exhibit. How should the script be completed so that each device configuration is saved into a JSON-formatted file under the device name? A. B. C. D.
Options
- AInsert after the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response)
- BInsert after the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(json.dumps(Response.text))
- CAppend to the body of the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(Response.text)
- DInsert immediately before the for loop: with open(f"{Hostname}.json", "w") as OutFile: OutFile.write(json.load(Devices))
Explanation
Option C is correct because the file-writing block must be appended inside (as part of the body of) the for loop so that a separate JSON file is created for each device using that device's hostname. Response.text already contains the raw JSON-formatted string returned by the HTTP/REST API call, so writing it directly with OutFile.write() produces a valid JSON file without any additional serialization.
Topics
Community Discussion
No community discussion yet for this question.