Save this video free

Python (Fall 2026) Module 12-2: Reading and Writing Files

Bill Moseley, Ph.D. - Computer Science Educator · 9:56 · Watch on YouTube

Part of Bakersfield College COMP B10. See all 47 lectures and search them

These notes were made with YouTube Collector. Paste any YouTube link and get the same: a summary, chapters and a searchable transcript.

Overview

Bill Moseley explains how Python file objects read text with `read()` and `readline()`, and how their pointer advances as content is consumed. He also demonstrates writing with modes such as `w`, `a`, and `x`, emphasizing that the chosen mode and file state affect whether data is replaced, appended, or read successfully.

Key takeaways

Chapters

0:00 Python `read()` Reads Entire Files or a Character Count
3:29 Python `readline()` Advances the File Pointer One Line at a Time
6:42 Python Write Modes, Appending Text, and Reopening Files

Keep these chapters and the full searchable transcript in your own library.

Transcript excerpt

0:01 So if I want to read from a file, now remember,  this only creates a file object. This doesn't get me what's in that file yet. If I want to get  what's in the file, I have to read the file. And there's a few different ways to do this. Okay.  All of them involve using a read method of the file object. So this would be a file object  that I already opened and attached to a file. If I do this, myFile.read with no arguments, it's  going to take the entire contents of that file and put them as a string into that strFileText  variable. It's going to take everything. If I give it a numeric parameter, you can see it's an  integer because we can't do fractional characters. What that means is you're going to read the  first 10 characters of that file. Then, okay, the

1:10 next one, read line, will read one line  from the file at a time. So let me show you how this looks. Okay. So, let's say I  have this file here. Where did I put that? You know what's helpful? If you're  50 years old and half blind, wearing glasses. That's nice. There  we go. Now I can see. Okay. So, I've got this intro.txt file here. And this is  just, you can see, five lines of plain text. It's not code. It's not anything special.  But if I want to play around with that, I'm just going to call this

2:04 fi, or fiIntro. So I know it's a  file object, and I'm going to open that. So I'm going to just say intro.txt for  reading. Okay. And so now if I say strText = read with no parameters,  and I print that out, str. Let's run that. Okay. So it just takes everything  that's in that and prints it out, including the

This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.

In this course

Related notes

Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.

Want the full transcript?

Save this video in YouTube Collector to get its complete searchable transcript, your own AI summaries, and a library that keeps every video you collect in one place.