Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 52)
52.
How can you append a list of numbers to a binary file named "data.bin"?
with open("data.bin", "wb") as file:
    numbers = [1, 2, 3, 4, 5]
    file.write(bytes(numbers))
append_binary("data.bin", [1, 2, 3, 4, 5])
with open("data.bin", "ab") as file:
    numbers = [1, 2, 3, 4, 5]
    file.write(numbers)
binary_append("data.bin", [1, 2, 3, 4, 5])
Answer: Option
Explanation:
Using open() in binary write mode and bytes() to write a list of numbers to a binary file.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.