In this video, learn how to use the tempfile module to create, write, and read temporary files. These files can be set to erase once closed, or at program termination.
- [Instructor] We can use the tempfile module…to create temporary files in Python,…but in order to use the tempfile module,…we have to import it.…And so, to import it, we'll go, import tempfile.…Now that we have access to it,…we'll go ahead and create a temporary file.…To do this, we'll create a variable, so, tempFile,…which will hold our temporary file that we create.…And then, to create the temporary file,…we'll access the module, so, tempfile.,…and then the TemporaryFile constructor there,…and that will create our temporary file.…
Now that our temporary file is stored…inside of tempfile, we'll go ahead and access tempFile,…and this is how we're going to write to the file.…And so, we'll go write, and what…we're going to want to write to this temporary file…is just a special number, and so we'll say,…Save this special number for me.…It'll be 5678, and then, 309.…And this is your special number that you're saving.…However, we're not done yet,…and that's because this write method takes a bytes object.…
And here, we have a string.…
- 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.