Python 3: Pocket Primer by James R. Parker

Python 3: Pocket Primer by James R. Parker

Author:James R. Parker [James R. Parker]
Language: eng
Format: epub
Publisher: Mercury Learning and Information
Published: 2017-03-15T04:00:00+00:00

All of these files, and indeed all files, have certain things in common. Some of these things can be ignored when writing Python programs, but others cannot.

Files have names. The first way to access a file is usually by specifying its name.

Files have a size. It is usually expressed in bytes, which is to say characters.

Basic operations on a file are read and write. To read from a file means to examine a byte (at least). Writing is the reverse process: a byte or bytes are copied from memory onto disk.

Files must be open before they can be used. To open a file a program must know its name, and then invoke the open function or program. The open function and many other file-related operations belong to the operating system of the computer, and not normally to the language. It’s one reason why so much software is not portable.

Only one program at a time can write to a file. Many programs can read a file simultaneously, but only one can write to it, and not while anyone else is reading it.

Another thing to consider is that text, and therefore text files, are a principal means for communication between humans and computers. It is critical that any scheme for writing text to a file takes into account the human aspects of text: sentences, lines, paragraphs, special characters, numbers, and so on. This chapter will be concerned with the way in which Python can use files, with files as a concept in general, and with how humans think of data and files.

How long does it take to access a block of data on the disk? The time to access a random data item can be estimated as 14.15 milliseconds. Disk is vastly slower than memory, and in order to use the data, it must be copied into memory. This is a bottleneck in many computer systems.


Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.