|
1.What is the data type of the value returned by the read() or readline() methods of a file object, assuming that file object is associated to a pure text file?
Select one or more:
a. int
b. list
c. It depends on the data type of the values stored in the file.
d. str
2.Which of the following methods of a file object reads the entire file into a single string?
Select one or more:
a. read_file_to_str()
b. read()
c. readline() if and only if there are no newline characters in the file
d. readlines()
3.Assume that there is a pure text file named data.txt in the current working directory, with the following format (4 lines, two columns per line, separated by a blank space, no leading blank spaces at the beginning of any line):
A 65
B 66
C 67
D 68
We want to write Python code that reads the file and creates a dictionary out of the file in a variable named d. Each line in the file describes a key-value pair of the dictionary, with the value in the first column being the dictionary key, and the value in the second column being the corresponding dictionary value. We want the dictionary values to be stored as integer numbers, i.e., values of type int.
Which of the following code snippets performs the work?
Select one or more:
a. d={line.strip()[0]:int(line.strip()[2]) for line in open("data.txt","r")}
b.
fin=open("data.txt","r")
file_contents=fin.read()
fin.close()
file_lines=file_contents.strip().split("\n")
d={}
for line in file_lines:
cols=line.split()
d[cols[0]]=int(cols[1])
c. d={line.split()[0]:int(line.split()[1]) for line in open("data.txt","r")}
d.
fin=open("data.txt","r")
d={}
for line in fin:
cols=line.split()
d[cols[0]]=cols[1]
fin.close()
4.Given the directory structure below, and assuming that the absolute path of the W8 folder is /W8 (i.e., the W8 folder resides in the root folder /), which of the following statements are true?
W8
├── bom_mel_olympic_park_monthly_mean_max_temp.txt
├── input_data_files/
│ ├── lactase_ex**.tsv
│ ├── lactase_gene.txt
│ └── mrna_to_amino_acids_mapping.tsv
└── Python_WS8_From_genes_to_proteins.ipynb
Select one or more:
a. The absolute path of the file named lactase_gene.txt is /W8/input_data_files/lactase_gene.txt.
b. Assuming that the current working directory is /W8, the relative path of the file named lactase_ex**.tsv is lactase_ex**.tsv.
c. Assuming that the current working directory is /W8, the relative path of the file named lactase_ex**.tsv is input_data_files/lactase_ex**.tsv.
d. The relative path of the file named bom_mel_olympic_park_monthly_mean_max_temp.txt is bom_mel_olympic_park_monthly_mean_max_temp.txt independently on the current working directory.
|
|