exam questions

Exam 350-401 All Questions

View all questions & answers for the 350-401 exam

Exam 350-401 topic 1 question 603 discussion

Actual exam question from Cisco's 350-401
Question #: 603
Topic #: 1
[All 350-401 Questions]

Which Python snippet should be used to store the devices data structure in a JSON file?

  • A.
  • B.
  • C.
  • D.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Darude
Highly Voted 2 years, 5 months ago
Selected Answer: A
reference: https://www.section.io/engineering-education/storing-data-in-python-using-json-module/
upvoted 12 times
...
AbdullahMohammad251
Most Recent 7 months, 2 weeks ago
Selected Answer: A
"json.dump()"- converts a Python dictionary into a JSON file. "json.dumpS()"- converts a Python dictionary into a JSON string. "json.load()"- converts a JSON file into a Python object. This makes C and D incorrect. B is also incorrect because it takes the entire Python object and converts it into a string, not even a JSON-formatted string.
upvoted 4 times
...
[Removed]
11 months ago
Selected Answer: A
A is correct
upvoted 1 times
...
[Removed]
11 months, 2 weeks ago
A is correct
upvoted 1 times
...
ccnp_core_2024
1 year ago
if is answers is "OutFile.Close()", then OutFile = open("devices.json","w") json.dump(Devices, OutFile) OutFile.Close() Traceback (most recent call last): File "main.py", line 14, in <module> OutFile.Close() AttributeError: '_io.TextIOWrapper' object has no attribute 'Close' ** Process exited - Return Code: 1 ** Press Enter to exit terminal
upvoted 1 times
Steve122
9 months, 1 week ago
Case sensitive. AttributeError: '_io.TextIOWrapper' object has no attribute 'Close': OutFile.Close() -> OutFile.close()
upvoted 2 times
...
...
andresga20
1 year, 8 months ago
Selected Answer: A
Tested all 4 of them on Visual Studio Code: A: works, right answer B: does not work properly, it just copies the data without making sure the formatting is good for json files C: creates an empty file D: errors out, the syntax is not right
upvoted 4 times
...
dapardo
1 year, 8 months ago
Selected Answer: A
I will go with A considering the differences between json.dump and json.dumps https://www.geeksforgeeks.org/python-difference-between-json-dump-and-json-dumps/
upvoted 3 times
...
eddgg
1 year, 9 months ago
Selected Answer: A
the main difference is that outfile.write(str(devices)) writes the string representation of the data directly to the file, while outfile.dump(devices, outfile) uses serialization to write the data in a specific format (e.g., JSON, YAML) to the file, preserving its original data structure and types
upvoted 2 times
...
teikitiz
1 year, 9 months ago
Selected Answer: A
"Devices" is already a dict, which prompts dump as the tool to write a file.
upvoted 2 times
...
msstanick
1 year, 10 months ago
Selected Answer: B
I got it tested - the correct one is B. Explanation A: Incorrect, there is no such a thing like json.dumb - there is a missing 's' -> dumbs B: Correct, worked fine on my py script. str(Devices) is doig the same thing as json.dumbs in this case - it is casting dict to str type C: Incorrect, the outcomes are not put into a file. It would have worked if it was OutFile.write(json.dumbs(Devices)) D: Incorrect, not only are we not putting anything into a file but it is also trting to change dicto to a dict which would cause an error
upvoted 2 times
Burik
1 year, 10 months ago
Actually both json.dump() and json.dumps() are valid Python methods, only slightly different. https://www.geeksforgeeks.org/json-dump-in-python/ https://www.geeksforgeeks.org/json-dumps-in-python/ Thing is, in the version of this question as shown here, both A and B will work. An alternative dump of this question shows A as wrong because it says OutFile.Close(), with an uppercase C, which is not a valid Python method. If you've been using json.dumb [lol?] of course it will throw an error because it doesn't exist as a method.
upvoted 1 times
...
...
snarkymark
2 years, 3 months ago
Choosing A. https://www.section.io/engineering-education/storing-data-in-python-using-json-module/
upvoted 2 times
...
mask_n_sorrow
2 years, 3 months ago
Selected Answer: C
Option A didn't work as you can see >>> import json >>> devices = {'switch':'blah', ... 'router':'ddd' ... } >>> outfile = open("devices.json",w) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'w' is not defined >>> with open("devices.json","w") as outfile: ... json.dumps(devices) File "<stdin>", line 2 json.dumps(devices) ^ IndentationError: expected an indented block >>> with open("devices.json","w") as outfile: ... json.dumps(devices) ... '{"switch": "blah", "router": "ddd"}' >>>
upvoted 1 times
ImFran
2 years, 3 months ago
in your test """ >>> outfile = open("devices.json",w) """ you forgot to put quotation marks around w...
upvoted 2 times
...
...
nushadu
2 years, 3 months ago
Guys, what version of Python they used in the scripts?
upvoted 1 times
...
milovnik1
2 years, 5 months ago
Selected Answer: A
A is correct, the same configuration can be found in multiple examples here: https://www.geeksforgeeks.org/json-dump-in-python/
upvoted 4 times
...
dancott
2 years, 5 months ago
Selected Answer: C
https://www.section.io/engineering-education/storing-data-in-python-using-json-module/#:~:text=Using%20json.,-dumps()&text=dumps()%20can%20be%20used,object%20into%20a%20JSON%20string.&text=dumps(data)-,The%20json.,be%20converted%20into%20JSON%20string.
upvoted 1 times
...
testcom680
2 years, 5 months ago
Selected Answer: A
I'll go for A
upvoted 4 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago