What does the 'b' modifier do when a file is opened using Python?

PythonServer Side ProgrammingProgramming

'b' modifier opens the file specified in binary mode. "binary" files are any files where the format isn't made up of readable characters. Binary files can range from image files like JPEGs or GIFs, audio files like MP3s or binary document formats like Word or PDF. In Python, files are opened in text mode by default. To open files in binary mode, when specifying a mode, add 'b' to it. 

example

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

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

raja
Published on 27-Dec-2017 17:21:15
Advertisements