A binary file is typically read and written using a fixed-size buffer. This is a demonstration of how to copy a binary file.
- [Instructor] To copy a binary file…we use the read and write methods of the file object.…Here in Kamodo I've opened a working copy of copy-bin.py,…from chapter 12 of the exercise files.…We have this input file, which is an image.…This is a picture of a train station in Berlin,…which I took on a trip overseas last year.…I happen to love the train stations in Europe…and the whole train system in Europe is just so wonderful…as compared to what we have here in the United States.…
I thought this was a particularly beautiful train station,…I took a number of pictures of it.…So we're going to use that for our data.…When I run this code, I'm just going to go ahead and run it,…so you can see it work.…You notice I get my same progress bar here.…Each bar represents 10 kbytes read and written…and my output file, now here is berlinecopy.jpeg.…When I open that, you'll see…that it's exactly the same picture.…So I've successfully copied a binary file.…You'll notice here, on line five,…when we open the file, we're opening it with the b now…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficiently (2017)with Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- 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.