You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose two.)
You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you use? (Choose two.)
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.
A. data = bytearray (16) bf.readinto (data) D. data = bytearray (binfile.read (16))
When all are tested, B & C error. A & D are correct.
A & D are the correct answers.
It is A,D
A and D are correct
Correct answers are A & D
A. is a typo and should be two lines because both B & C will cause error.
A & D are the correct answers.
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
Confirmed, A & D.
How is it A & D?can you please elaborate on it.