© Joey Bernard 2016

Joey Bernard, Python Recipes Handbook, 10.1007/978-1-4842-0241-8_4

4. Files and I/O

Joey Bernard

(1)Fredericton, New Brunswick, Canada

For any type of data processing, files are absolutely necessary. It very quickly becomes the case that there is too much information to have the user input it manually. You need to be able to handle importing information directly from files of various types.

This chapter, you will look at the most common tasks you need to be able to handle in order to read and write files. You’ll also look at how to deal with other forms of input and output.

4-1. Copying Files


You need to copy files from one location to another.


There are two functions from the shutil module that can be used to copy ...

Get Python Recipes Handbook: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.