Exam 350-401 All QuestionsBrowse all questions from this exam
Question 416

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:

    Correct Answer:

Discussion
uzbin

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.

nhawley

Agreed, you should reference the variable input_file

Caradum

uzbin is right.

Makaveli1

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.

nushadu

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

HarwinderSekhon

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)

danman32

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.

Zendahr

with open(input_file) as text: out_file = open("Json-Output.json", "w") out_file.close()

SeMo0o0o

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() )))

SeMo0o0o

with open(input_file) as text: out_file = open("Json-Output.json", "w" out_file.close() ......................

kewokil120

UZBIN is right.