exam questions

Exam 350-401 All Questions

View all questions & answers for the 350-401 exam

Exam 350-401 topic 1 question 416 discussion

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

DRAG DROP -
An engineer plans to use Python to convert text files that contain device information to JSON Drag and drop the code snippets from the bottom onto the blanks in the code to construct the request. Not all options are used.
Select and Place:

Show Suggested Answer Hide Answer
Suggested Answer:

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
uzbin
Highly Voted 2 years, 8 months ago
File 'raw-data.tx' is referenced by the variable input_file, so first text box should contain - with open(input_file) as text: Rest looks correct.
upvoted 35 times
nhawley
2 years, 6 months ago
Agreed, you should reference the variable input_file
upvoted 1 times
...
Caradum
2 years, 5 months ago
uzbin is right.
upvoted 1 times
...
Makaveli1
2 years, 4 months ago
No, the variable "input_file" will contain text string 'raw-data.txt', not the file. To open the file you use the context manager. >>> input_file = 'raw-data.txt' >>> input_file 'raw-data.txt' The given answer is correct.
upvoted 2 times
danman32
1 year, 9 months ago
the function open() requires text as input option, whether that is literal or through a variable containing text that specifies the file name. The given answer specifies an undefined variable.
upvoted 2 times
...
nushadu
2 years, 4 months ago
you are wrong; with open('some_file.txt', 'w') as f: f.write('hello') <<<<<<<<<<<< write text into the file with open('some_file.txt') as f: print(f.read()) <<<<<<<<<<<<<<<<< read hello <<<<<<<<<<<<<<< output my_file = 'some_file.txt' <<<<<<<<<<<<< just variable with open(my_file) as f: <<<<<<<<<<<<< use it in the code print(f.read()) hello
upvoted 2 times
...
HarwinderSekhon
1 year, 11 months ago
Tested -- myfilename = 'dummy.txt' # open the file for reading (replace 'file.txt' with your file name) with open(myfilename, 'r') as file: # read the content of the file data = file.read() # print the content print(data)
upvoted 2 times
...
...
...
AbdullahMohammad251
Most Recent 7 months ago
The open () method in Python expects a file path in double quotes as a parameter. without quotes, you would get an error: "NameError: name 'raw-data' is not defined." The correct answer is: with open(input_file) as text: out_file = open("Json-Output.json", "w") out_file.close()
upvoted 2 times
AbdullahMohammad251
7 months ago
https://stackoverflow.com/questions/62347631/why-is-it-possible-to-pass-a-file-as-a-string-to-the-open-function https://www.freecodecamp.org/news/with-open-in-python-with-statement-syntax-example/
upvoted 1 times
...
...
maciek8131
8 months, 2 weeks ago
with open(input_file) as text: out_file = open("Json-Output.json", "w") out_file.close() That is Good
upvoted 3 times
...
Zendahr
10 months, 2 weeks ago
with open(input_file) as text: out_file = open("Json-Output.json", "w") out_file.close()
upvoted 2 times
...
[Removed]
11 months, 2 weeks ago
given answer is wrong import json input_file = 'raw-data.txt' dictionary_1 = {} fields = ['Device type', 'IP_Address', 'IOS_type', 'Username', 'Password'] # (Open the input file for reading): ((( with open(input_file) as text: ))) device_number = 1 for line in text: description = list(line.strip().split(None, 4)) print(description) Device_Number = 'Device' + str(device_number) i = 0 # (Open the output file for writing): ((( out_file = open("Json-Output.json", "w") ))) json.dump(dictionary_1, out_file, indent=4) # (Close the output file after writing): ((( out_file.close() )))
upvoted 2 times
[Removed]
10 months, 3 weeks ago
with open(input_file) as text: out_file = open("Json-Output.json", "w" out_file.close() ......................
upvoted 1 times
...
...
kewokil120
2 years, 3 months ago
UZBIN is right.
upvoted 1 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