4.7 Flashcards

1
Q

what are the two categories of files in Python?

A

Text files, and Binary files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

EOL

A

End of Line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A_____ is structured as a sequence of lines, where each line includes a sequence of characters.

A

Text file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Each line in a text file is terminated with a special character called

A

EOL, or End of Line character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the most common EOL?

A

A comma, or a newline character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A ______ character can be used to tell the interpreter that the next character - following it - should be treated as a new line.

A

a backslash

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the function of an EOL?

A

It ends the current line and tells the interpreter a new one has begun.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A _____ is any type of file that is not a text file.

A

Binary file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

T or F: there must be an application that can read and interpret binary files.

A

True. because of their nature, binary files can only be processed by an application that knows or understands the file’s structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Python File Handling (Order the following):

Read or Write a file, close a file, Open a file.

A

Open a file. Read or write a file. Close a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Name all Text File Opening Modes.

A

r, r+, w, w+, a, a+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

r

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A

w

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Name the file opening mode:

_____ opens a file for both reading and writing. The file pointer is placed at the beginning of the file.

A

r+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

w+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

a

17
Q

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

a+

18
Q

Name the attribute:

_____ returns true if file is closed, false otherwise.

A

file.closed

19
Q

Name The Attribute:

_____ returns name of the file.

A

file.name

20
Q

Name The Attribute:

____ returns access mode with which file was opened.

A

file.mode

21
Q

Which python function do you use to get a file?

A

open () function

22
Q

the syntax to open a file object in python:

A

file_object = open (“filename”, “mode”)

23
Q

the syntax of write function:

A

fileObject.write(string)

24
Q

T or F: the write function does not add a newline character (‘/n’) to the end of the string.

A

True

25
Q

the syntax of closing a file:

A

fileObject.close() or myfile.close()