click below
click below
Normal Size Small Size show me how
files
python files
Question | Answer |
---|---|
file definition | sequence of bytes stored on a secondary memory device, such as a disk drive. A file could be a text document or spreadsheet, an html file, or a Python module. Such files are referred to as text files. All files are managed by the file system |
file system | the component of a computer system that organizes files and provides ways to create, access, and modify files. provides a uniform view of the files that hides the differences between how files are stored on the different hardware devices. |
directories | Files are grouped together into directories or folders. A folder may contain other folders in addition to (regular) files. file system organizes files and folders into a tree structure, typically drawn upside down |
root directory | The folder on top of the hierarchy is called the root directory. Every folder and file in a file system has a name. However, a name is not sufficient to locate a file efficiently. |
pathname | Every file can be specified using a pathname that is useful for locating the file efficiently. The file pathname can be specified in two ways. |
absolute pathname of a file | consists of the sequence of folders, starting from the root directory, that must be traversed to get to the file. represented as a string, sequence of folders is separated by forward (/) or backward (\) slashes, depending on the operating system. |
current working directory | . When using the command shell, the current working directory is typically listed at the shell prompt. When executing a Python module, the current working directory is typically the folder containing the module. |
relative pathname | of a file is the sequence of directories that must be traversed, starting from the current working directory, to get to the file. |
parent folder | , which is the folder containing the current working directory. The double-period notation (..) |
file mode read | infile = open(‘example.txt’, ‘r’) Reading mode (default) |
file mode write | Writing mode; if the file already exists, its content is wiped infile = open(‘example.txt’, ‘w’) |
file mode append | Append mode; writes are appended to the end of the file infile = open(‘example.txt’, ‘a’) |
file mode read and write | Reading and writing mode (beyond the scope of this book) infile = open(‘example.txt’, ‘r’+) |
file mode text | Text mode (default) infile = open(‘example.txt’, ‘t’) Text files, however, are treated as encoded files using some encoding. |
file mode binary | Binary mode infile = open(‘example.txt’, ‘b’) binary files are treated as a sequence of bytes and are not decoded when read or encoded when written to. |
file object | The open() function returns an object of an Input or Output Stream type that supports methods to read and/or write characters. Different modes will give us file objects of different file types. the file type will support all or some of the methods |