What Kinds of Files Are There?

There are many kinds of files. Text files, music files, videos, and various word processor and presentation documents are common. Text files contain only characters; all the other file formats include formatting information that is specific to that particular file format, and in order to use a file in a particular format you need a special program that understands that format.

Try opening a Microsoft PowerPoint (.ppt) file in a text editor such as Apple TextEdit, Microsoft Notepad, or one of the many Linux text editors such as vi, emacs, and gedit. Scroll through it; you’ll see what looks like gobbledygook. This is because those files contain a lot of information: what’s a title, what are the headings, which words are bold, which are italic, what the line height should be, what the margins are, what the links to embedded content are, and a lot more. Without a program such as Microsoft PowerPoint, .ppt files are unusable.

Text files, on the other hand, don’t contain any style information. They contain only human-readable characters. You can open a text file in any text editor and read it. You can’t include style information in text files, but you gain a lot in portability.

Plain-text files take up very little disk space. Compare the size of an empty text file to “empty” OpenOffice, Apple Pages, and Microsoft Word documents:

images/fileproc/emptyfilesizes.png

The empty text file is truly empty: there is no styling information or metadata such as author information, number of pages, or anything else in the file. This makes text files much faster to process than other kinds of documents, and any editing program can read an empty text file.

The Python programs you have been writing are text files. By themselves, they are only characters in a file. But combined with a Python interpreter, these Python text files are robust: you can express a powerful algorithm following Python’s syntax rules, and the interpreter will follow your instructions.

This power comes from applications that can process text files that are written with a particular syntax. Web browsers read and process HTML files, spreadsheets read and process comma-separated value files, calendar programs read and process calendar data files, and other programming language applications read and process files written with a particular programming language syntax. A database, which you’ll learn about in Chapter 17, Databases, is another way to store and manage data.

In the next section, you’ll learn how to write programs that open and print the contents of a text file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.10.1