Read binay file with readinto method


i am preparing tp pass PCAP exam, so in section Certified Associate in Python (PCAP) Programming Certification | KodeKloud

whats the meaning of defining data twice :slight_smile:
to intialize with zero
to read binary file and assign this content in the same var data

Best regards

Hi Mourad, Thanks for your query.

data = bytearray(10) //We are initialising data here
bf.readinto(data) // we are loading the content of open file to data list

in the for loop we are reading data list and printing the byte content in hex. We are not defining data twice here.

Hope this clarifies your query