0PricingLogin
NLP Academy · Lesson

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

  1. Strings, Characters, and Encodings
  2. Reading Text Files Into Python
  3. Counting Words and Characters
  4. Building Your First Word Frequency Table
← Back to NLP Academy