Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to open a binary file in append mode with Python?

How do I open a binary file in append mode in Python?


1 Answer
Manogna

"Binary" files are any files where the format isn't made up of readable characters. Binary files can range from image files like GIFs, audio files like MP3s or binary document formats like Word or PDF. To open files in binary append mode, when specifying a mode, add 'ab' to it. For example,

 f = open('my_file.mp3', 'ab')
file_content = f.read()
f.close()
 

Above code opens my_file.mp3 in binary append mode and stores the file content in file_content variable.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.