Files
You use different kinds of files all the time! Text files, python programs, images, pdfs, audio and video files. Lots of applications are focused on doing different tasks with files. Instagram? Download and display image files. iTunes? Show and play audio files. Photoshop? Microsoft Word? Audacity? They're specialized programs for editing different kinds of files (photos, rich text documents, and audio). Even a web browser is, in some ways, a fancy file viewer, for files shared across different servers.
Files have so many different uses for a few reasons:
- Persistent: they stick around after a program is done running. They're saved.
- Flexible: they can represent lots of different kinds of data
- Shareable: you can share a file between programs, or between computers over a network
Use Cases
You may encounter many use cases to integrate files within your program:
- Data that somebody shared with you as a file. For example, a list of sensor readings stored in a file and you need to process.
- Saving user configurations like font size, color, selected theme, etc.
- Saving user logs. Web servers for example save their logs in files.
Files are super powerful... but they can also be pretty complicated. Python offers a ton of different libraries and functions for working with files. You'll focus on learning to use some of the most useful functions this week - reading and writing files, moving them around, and organizing them in directories.
Learning Outcomes
After this week, you will be able to:
- Use python's built-in tools for managing files and directories
- Read text from files and write text to files
- Check different information about files, like the size or type of a file
- Create, destroy, move, or change files and directories