Exam PCAP All QuestionsBrowse all questions from this exam
Question 72

You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose two.)

    Correct Answer: A, D

    To read 16 bytes from a binary file into a bytearray called data, you would use the following lines: data = bytearray(16) followed by bf.readinto(data), which pre-allocates a bytearray of 16 bytes and then reads up to 16 bytes into this array. Alternatively, you can use data = bytearray(binfile.read(16)), which reads 16 bytes from the binary file and directly converts it into a bytearray. These two methods are correct for achieving the intended operation.

Discussion
macxszOptions: AD

A. data = bytearray (16) bf.readinto (data) D. data = bytearray (binfile.read (16))

TheNetworkStudentOptions: AD

When all are tested, B & C error. A & D are correct.

rocky48Options: AD

A & D are the correct answers.

luckymukiOptions: AD

It is A,D

Ram5678Options: AD

A and D are correct

JnanadaOptions: AD

Correct answers are A & D

stuartzOptions: AD

A. is a typo and should be two lines because both B & C will cause error.

wts28Options: AD

A & D are the correct answers.

sadako11Options: AD

readinto(b) Read up to len(b) bytes into b, and return the number of bytes read. The object b should be a pre-allocated, writable array of bytes, either bytearray or memoryview. I think answer A should be two separate lines: data = bytearray (16) => 16 bytes bytearray named 'data' bf.readinto (data) => read 16 bytes (the length of the byte array) into the bytearray named 'data' D: data = bytearray (binfile.read (16)) =>reading 16 bytes form the binary file and putting it in a bytearray called 'data' A,D are the right answers

dougie_fr3shOptions: AD

Confirmed, A & D.

karans

How is it A & D?can you please elaborate on it.