Module 6: Files Flashcards
A ________ is a sequence of ______ which are numbers each between 0 and 255.
file, byte
The meaning of the bytes depends on the _______ of the file.
format
In a _______ file each byte or group of bytes corresponds to a number, letter, punctuation mark or special character.
text
When a text file is open, it is an ________ which gives the contents of the file, one time at a time.
iterable
To read a text file, must first ______ and later ______ it.
open
close
Use the pattern _____ ___________ ____ ________ to open the file, then in a code block use iterable ________. This will automatically _______ the file.
with open(filename, ‘r’) as myfile
myfile
close
The two arguments for open are _______ indicating ________ of the file to open and _______ to indicate what to do with the file such as ______ or _______.
str
name
str
read
write
When writing text files at the end of every line there must be _______
‘\n’
A ______ file is a special text file that can be looked at directly. To read these files use the _____ module.
CSV
csv
To use the csv module type: with open(_____, _______) as ______
filename
‘r’ or ‘w’
csvfile
The function ___________ automatically uses the first line as the names of the columns and turns the rest of the lines into dictionaries.Write statement: _________ = _________
csv.DictReader(csvfile)
dictreader = csv.DictReader(csvfile)
*csvfile can be anything, its what the file was renamed when it was opened
For JSON file format, import _______ and load all the data using _________.
json
data = json.load(jfile)
To dump a value to an already open file for a JSON file use __________.
json.dump(obj, fp)
value = object
already open file = fp
dont need to do an assignment for json.dump(obj, fp)
In JSON files the keys can only be ________ and will convert ________ to ______.
str
int
str
If indices are used for csv file it splices ________. Ex. alllines[1:] would return _________.
lines
all the lines of the file except the first.