Chapter 8. Input and Output
To be useful, a program needs to communicate with the world around it. It needs to interact with the user, or read and write files, or access Web pages, and so on. In general, we refer to this as input and output, or I/O for short.
We’ve already seen basic console I/O, which involves printing messages and using the
input function to read strings from the user. Now we’ll see some string formatting that lets you make fancy output strings for console I/O and anywhere you need a formatted string.
Then we’ll turn to file I/O, which is all about reading and writing files. Python provides a lot of support for basic file I/O, making it as easy as possible for programmers. In particular, we’ll see how to use text files, binary ...