Binary Files
We'll cover the following...
Not all files contain text. Some of them contain pictures of my dog.
Press + to interact
an_image = open('beauregard.jpg', mode='rb') #①print (an_image.mode) #②#rbprint (an_image.name) #③#'beauregard.jpg'print (an_image.encoding) #④#Traceback (most recent call last):# File "__ed_file.py", line 8, in <module># print (an_image.encoding) #\u2463#AttributeError: '_io.BufferedReader' object has no attribute 'encoding'
① Opening a file in binary mode is simple but subtle. The only difference from opening it in text mode is that the mode
parameter ...
Access this course and 1400+ top-rated courses and projects.