Module 6: Files Flashcards

1
Q

A ________ is a sequence of ______ which are numbers each between 0 and 255.

A

file, byte

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

The meaning of the bytes depends on the _______ of the file.

A

format

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

In a _______ file each byte or group of bytes corresponds to a number, letter, punctuation mark or special character.

A

text

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

When a text file is open, it is an ________ which gives the contents of the file, one time at a time.

A

iterable

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

To read a text file, must first ______ and later ______ it.

A

open
close

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

Use the pattern _____ ___________ ____ ________ to open the file, then in a code block use iterable ________. This will automatically _______ the file.

A

with open(filename, ‘r’) as myfile
myfile
close

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

The two arguments for open are _______ indicating ________ of the file to open and _______ to indicate what to do with the file such as ______ or _______.

A

str
name
str
read
write

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

When writing text files at the end of every line there must be _______

A

‘\n’

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

A ______ file is a special text file that can be looked at directly. To read these files use the _____ module.

A

CSV
csv

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

To use the csv module type: with open(_____, _______) as ______

A

filename
‘r’ or ‘w’
csvfile

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

The function ___________ automatically uses the first line as the names of the columns and turns the rest of the lines into dictionaries.Write statement: _________ = _________

A

csv.DictReader(csvfile)
dictreader = csv.DictReader(csvfile)
*csvfile can be anything, its what the file was renamed when it was opened

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

For JSON file format, import _______ and load all the data using _________.

A

json
data = json.load(jfile)

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

To dump a value to an already open file for a JSON file use __________.

A

json.dump(obj, fp)

value = object
already open file = fp

dont need to do an assignment for json.dump(obj, fp)

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

In JSON files the keys can only be ________ and will convert ________ to ______.

A

str
int
str

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

If indices are used for csv file it splices ________. Ex. alllines[1:] would return _________.

A

lines
all the lines of the file except the first.

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

The ________ is the _______ line of a csv file and describes what fields are present in the file.

A

header
first

17
Q

Each item in a file is a _______. can use _____ or _______ to convert it.

A

str
int()
float()

18
Q

Str, int and float use _______ brackets to change the type of a value.

A

round
()

19
Q

________ files are good for rows of data whereas tree-like information is better stored in _______ files.

A

csv
json

20
Q

A _______ file can encode str, int, float, bool, None, list/dictionary.

A

JSON

21
Q

A JSON file should always contain __________, typically ______ or _______.

A

one value
list
dictionary

22
Q

__________ take a file object containing a value in JSON format and returns the value.

A

data=json.load()

23
Q

___________ takes any appropriate value and file object and writes the value to the file in JSON format.

A

json.dump

24
Q

___________ takes one iterable (from open) and returns a new iterable that gives data one line at a time. To access this use format: _________________

A

csv.reader
reader = csv.reader(csvfile)