File I/O Flashcards
What does I/O stand for?
Input something from the outside world
Output something to the outside world
One of the most common ways we us I/O is
to read / write files
example of using I/O: we develop a script to compress images
we need to INPUT IMAGE
and OUTPUT COMPRESSED IMAGE
What is Open?
Python’s built-in function that allows us to open and write to files
example of what we can do:
open(‘name of file’)
you have to manually close the file after you are finished with the file
open has a default param, mode. It is set to ‘r’ for read. Can be changed to ‘w’ for write or ‘r+’
most common modes are:
read, write, and append
File I/O errors
common pattern when working with File I/O is to put them in a Try Except block
try:
code
except FileNotFoundError:
code
or..
except IOError: