In this video, learn how to read a file line-by-line and edit it if necessary. Kathryn demonstrates using the example of replacing a set of initials on a high score board.
- [Instructor] We've read files, we've written to files,…but we can actually iterate the files…by looking at just one line at a time.…Here on the second line…we have our scores.txt saved in this myFile variable.…We can look at this file over here,…and we have three lines in it,…with each line having some initials…and the respective score.…Going back to the code,…if we just want to read one line…we can go something like,…print, my one line,…and then we'll go ahead and print out the line…which here will be…myFile.readLine.…
And this will read one line of the file,…and that one line is just that first line…with the one set of initials and the score.…Now read line does change the position of the seek pointer,…and so we'll want to reset the seek pointer back to zero,…and we can do this with what we learned in the last video…with myFile.seek(0),…so that way when we read again…we'll be reading from the very beginning of the file.…Because our file can be broken up into lines…we can iterate through each line of that file.…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
Learning the Standard PHP Librarywith David Powers3h 24m Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.