Reading Text Files Into Python
Open a document and load its contents.
Real Text Lives in Files
Most NLP work starts with documents stored on disk. Your first job is to load that text from a file into a Python string. 📄
Open a File With open
The open function connects Python to a file. You give it a path and a mode like r, which means read.
f = open("notes.txt", "r")
text = f.read()
f.close()All lessons in this course
- Strings, Characters, and Encodings
- Reading Text Files Into Python
- Counting Words and Characters
- Building Your First Word Frequency Table