4.7 Flashcards
(25 cards)
what are the two categories of files in Python?
Text files, and Binary files
EOL
End of Line
A_____ is structured as a sequence of lines, where each line includes a sequence of characters.
Text file
Each line in a text file is terminated with a special character called
EOL, or End of Line character.
What is the most common EOL?
A comma, or a newline character.
A ______ character can be used to tell the interpreter that the next character - following it - should be treated as a new line.
a backslash
What is the function of an EOL?
It ends the current line and tells the interpreter a new one has begun.
A _____ is any type of file that is not a text file.
Binary file
T or F: there must be an application that can read and interpret binary files.
True. because of their nature, binary files can only be processed by an application that knows or understands the file’s structure.
Python File Handling (Order the following):
Read or Write a file, close a file, Open a file.
Open a file. Read or write a file. Close a file.
Name all Text File Opening Modes.
r, r+, w, w+, a, a+
Name the file opening mode:
____ opens a file for reading only. The file pointer is placed at the beginning of the file. This is the default mode
r
Name the file opening mode:
_____ opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for reading and writing.
w
Name the file opening mode:
_____ opens a file for both reading and writing. The file pointer is placed at the beginning of the file.
r+
Name the file opening mode:
______ opens a file for both writing and reading. Overwrites the existing file if the file exists. if the file doesn’t exist, creates a new file for reading and writing.
w+
Name the file opening mode:
____ opens a file for appending. the file pointer is at the end of the file is the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
a
Name the file opening mode:
____ opens a file for both appending and reading. The file pointer is at the end of the file, if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
a+
Name the attribute:
_____ returns true if file is closed, false otherwise.
file.closed
Name The Attribute:
_____ returns name of the file.
file.name
Name The Attribute:
____ returns access mode with which file was opened.
file.mode
Which python function do you use to get a file?
open () function
the syntax to open a file object in python:
file_object = open (“filename”, “mode”)
the syntax of write function:
fileObject.write(string)
T or F: the write function does not add a newline character (‘/n’) to the end of the string.
True