Files Preparation
Overview
Python is a fantastic language for processing data files and is frequently used in other disciplines for that exact purpose. Today is focused on how to work with text files.
Basic Learning Objectives
Before class, you should be able to:
- Open, read from, and write to a text file in Python
- Define csv format
Advanced Learning Objectives
After class, you should be able to:
- Use the
read,readline, andreadlinesmethods appropriately - Solve problems that involve analyzing the content of files
- Solve problems that involve writing to files
Resources
You should read/watch the following:
- 11.1 Working with Data Files
- 11.2 Reading a File
- 11.3 Alternative File Reading Methods
- 11.4 Iterating over lines in a file
- 11.8 Writing Text Files
- 11.9 CSV Format
- 11.10 Reading in data from a CSV File
Checks
Submit answers to the following on Moodle:
- Checkpoint 11.3.3: Provide code to find the number of characters in a file
school_prompt2.txtand assign that value to the variablenum_char. - Checkpoint 11.4.1: Provide code to find out how many lines are in a file
emotion_words.txt. Save this value to the variablenum_lines. Do not use thelenmethod. - What is some data that you’d like to be able to process with Python?