Python Programming - Reading and Writing Files - Discussion

Discussion Forum : Reading and Writing Files - General Questions (Q.No. 74)
74.
How can you write a list of tuples to a binary file named "data.bin"?
with open("data.bin", "wb") as file:
    tuples = [(1, 'a'), (2, 'b'), (3, 'c')]
    file.write(pickle.dumps(tuples))
binary_write("data.bin", [(1, 'a'), (2, 'b'), (3, 'c')])
with open("data.bin", "ab") as file:
    tuples = [(1, 'a'), (2, 'b'), (3, 'c')]
    file.write(tuples)
write_binary("data.bin", [(1, 'a'), (2, 'b'), (3, 'c')])
Answer: Option
Explanation:
Using open() in binary write mode and pickle.dumps() to write a list of tuples 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.