Like most languages, Python distinguishes between text and binary files. This lesson describes this important distinction.
- [Instructor] Because of the diversity of computers and operating systems in the world, some systems handle text files differently than others. For example, this is a text string with the word string in it. The English word string has six letters. This is followed by a metacharacter that indicates the end of the line. This is sometimes referred to as the new line character, and is generally represented by a backslash and a lowercase n. The history of line endings is long and convoluted.
In many systems it is represented by a single line feed character, ASCII 10 decimal, or zero A hex. These systems include most Unix-based systems, including modern Macs. In this case, the string has seven bytes, including the line feed. In other systems, a new line is represented by a carriage return character, ASCII 13 decimal, or zero D hex. These systems are mostly obsolete, including the Apple II and classic Macs, TRS-80 and old Commodore systems.
In this case, the string has seven bytes, including the carriage return. Microsoft Windows machines use a sequence of both carriage return and line feed characters, in that order. Other older systems, including CP/M, OS/2, and old Digital Equipment minicomputers, use this line ending. In this case, the string has eight bytes, including the carriage return and the line feed. Because of the need to properly recognize any combination of these line endings, most systems have separate modes for opening text files and non-text, or binary files.
We'll discuss these two file modes in the rest of this chapter.
- 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 Efficientlywith Michele Vallisneri2h 15m Intermediate
Learning Python Web Penetration Testingwith Christian Martorella2h 49m 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.