In this video, Kathryn teaches you how to open and close files using Python's built-in functions, as well as some of the methods associated with the files themselves. She shows you how to create a file, look at some attributes of the file, and write to the file yourself in Python.
- Before we start messing with files in Python…we actually need to create a file.…And so here I'm going to go up to file, new,…just creating a new file in this current directory…where the Python file I'm running is.…And I'm just going to call this new file scores.txt.…And here it is, it's in that same directory…and we are just going to keep this file blank.…We're going to save it and we're actually going to mess with it…inside of our Python code.…To get access to this file we'll actually create…a variable called myFile in here.…
And then we'll go open, scores.txt,…so the name of the file we want to open…and then w for the mode that we want to open it in.…And here w stands for write.…If we put r here it would be read,…r+ would be read and write, a for append,…but we're going to keep it w for now.…Once we open this file then it's going to be saved…inside of this myFile variable,…and that's what we'll use to access the scores.txt file…in the future for this Python code.…
Now that we have it open, we're going to go ahead…
- 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.