一、判断题(共10小题,10分)
题型得分 10
文件对象的seek()方法用来返回文件位置指示器(文件指针)的当前位置。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
好的习惯,文件使用完毕后必须显式关闭文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
CSV文件是纯文本文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
为了防止文件中已存在的数据被意外清除,在打开文件前可以检测该文件是否存在。使用os.path模块中的isdir方法判断一个文件是否存在。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
以写模式打开的文件无法进行读操作。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
Python第三方扩展库openpyxl支持Excel文件的读写操作。
(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
打开文件的含义是指将文件对象与外存上的文件建立联系。成功打开文件后,对该文件的操作都将通过文件对象来完成。
(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
文件默认以二进制文件模式打开。打开文本文件要显式指定文本文件模式。
(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
序列化指的是从字节流中提取出对象的过程。(1分)
A. 对
B. 错
我的答案:
B
题目得分 1
参考答案:
B
内存文件不是存放在外存上的真正文件,而是存放在内存中的虚拟文件。(1分)
A. 对
B. 错
我的答案:
A
题目得分 1
参考答案:
A
二、填空题(共15小题,30分)
题型得分 26
下面程序的输出结果为________ (注意:不要有任何多余的空格)。
def main():
outfile = open(“temp.txt”, “w”)
outfile.write(“Hello\n”)
outfile.write(“Aloha\n”)
outfile.close()
infile = open(“temp.txt”, “r”)
text = “”
for line in infile:
text += line.rstrip()
infile.close()
print(text)
main()
(2分)
我的答案:
HelloAloha
题目得分 2
参考答案:
HelloAloha
下面程序执行后,文件temp.txt中内容是________。
def main():
fun(“temp.txt”, “amazing”)
fun(“temp.txt”, “awesome”)
def fun(filename,s):
outfile = open(filename, “w”)
outfile.write(s)
outfile.close()
main()
【来源】
《Python程序设计基础》第10章思考与练习。
(2分)
我的答案:
amazingawesome
题目得分 0
参考答案:
awesome
下面程序的输出结果为________ 。
def main():
iofile = open(“temp.txt”, “w+”)
for i in range(1, 10):
iofile.write(str(i))
iofile.seek(7)
print(iofile.read(1))
iofile.close()
main()
【来源】
《Python程序设计基础》第10章思考与练习。
(2分)
我的答案:
8
题目得分 2
参考答案:
8
下面程序的输出结果为________ 。
def main():
x = 20
y = 30
outfile = open(“temp.txt”, “w”)
outfile.write(str(x) + " " +str(y))
outfile.close()
infile = open(“temp.txt”,“r”)
s = infile.read()
numbers = [eval(value) for value in s.split()]
for number in numbers:
print(number, end=’#’)
infile.close()
main()
(2分)
我的答案:
20#30#
题目得分 2
参考答案:
20#30#
下面程序的输出结果为________ (注意:不要有任何多余的空格)。
def main():
lst = [“Hello”, “Aloha\n”]
outfile = open(“temp.txt”, “w”)
outfile.writelines(lst)
outfile.close()
infile = open(“temp.txt”, “r”)
text = infile.read().rstrip()
infile.close()
print(text)
main()
(2分)
我的答案:
HelloAloha
题目得分 2
参考答案:
HelloAloha
对文件进行写入操作之后,(注:填写英文)方法用来在不关闭文件对象的情况下强制将缓冲区内容写入文件。(2分)
我的答案:
flush
题目得分 2
参考答案:
flush()、flush
下面程序的输出结果为 (注意:不要有任何多余的空格)。
f = open(“temp.txt”, “w”)
f.write(“Lux et Veritas”)
f.close
f = open(“temp.txt”, “rb”)
f.read(3)
f.seek(4,1)
print(f.tell())
(2分)
我的答案:
7
题目得分 2
参考答案:
7
解决数据永久性保存的有效方式是使用________(注:填写中文)。
(2分)
我的答案:
题目得分 0
参考答案:
文件
文件使用完毕后必须关闭文件。(注:填写英文)方法用来显式关闭文件。(2分)
我的答案:
close
题目得分 2
参考答案:
close()、close
Python内置函数(注:填写英文)用来打开或创建文件并返回文件对象。(2分)
我的答案:
open
题目得分 2
参考答案:
open()、open
使用上下文管理________(注:填写英文单词)语句可以自动管理文件对象,不论何种原因,都能保证文件被正确关闭。(2分)
我的答案:
with
题目得分 2
参考答案:
with
若有以下程序:
1 f = open(“temp.txt”,“w+”)
2 f.write(“Lux et Veritas”)
3 f.seek(4,1)
程序中存在的错误在第________行(注:填写阿拉伯数字)。(2分)
我的答案:
3
题目得分 2
参考答案:
3
Python提供了一个专门处理CSV文件的________(注:填写英文)模块。
(2分)
我的答案:
csv
题目得分 2
参考答案:
csv
通常有两种类型的文件:文本文件和________(注:填写中文)。(2分)
我的答案:
二进制文件
题目得分 2
参考答案:
二进制文件
下面程序的输出结果为________ (注意:不要有任何多余的空格)。
f = open(“temp.txt”,“w+”)
f.write(“Lux et Veritas”)
f.seek(7)
s = f.read(3)
f.close()
print(s)
(2分)
我的答案:
Ver
题目得分 2
参考答案:
Ver
三、单项选择题(共20小题,40分)
题型得分 40
打开文件C:\scores.txt进行读操作,使用( )。
(2分)
A. infile = open(“C:\scores.txt”, “r”)
B. infile = open(“C:\scores.txt”, “r”)
C. infile = open(file = “C:\scores.txt”, “r”)
D. infile = open(file = “C:\scores.txt”, “r”)
我的答案:
B
题目得分 2
参考答案:
B
打开文件C:\scores.txt进行写操作,使用( )。
(2分)
A. outfile = open(“C:\scores.txt”, “w”)
B. outfile = open(“C:\scores.txt”, “w”)
C. outfile = open(file = “C:\scores.txt”, “w”)
D. outfile = open(file = “C:\scores.txt”, “w”)
我的答案:
B
题目得分 2
参考答案:
B
从infile文件对象读取2个字符,使用( )。
(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
A
题目得分 2
参考答案:
A
打开文件C:\scores.txt追加数据,使用( )。
(2分)
A. outfile = open(“C:\scores.txt”, “a”)
B. outfile = open(“C:\scores.txt”, “rw”)
C. outfile = open(file = “C:\scores.txt”, “w”)
D. outfile = open(file = “C:\scores.txt”, “w”)
我的答案:
A
题目得分 2
参考答案:
A
下列( )说法是错误的。
(2分)
A. 当打开一个文件进行写操作,如果文件不存在,创建一个新文件
B. 当打开一个文件进行写操作,如果文件已经存在,这个存在的文件被新文件覆盖
C. 当打开一个文件进行写操作,如果文件已经存在,出现一个错误
我的答案:
C
题目得分 2
参考答案:
C
下列( )说法是正确的。
(2分)
A. 当打开一个文件进行读操作,如果文件不存在,出现一个错误
B. 当打开一个文件进行写操作,如果文件不存在,出现一个错误
C. 当打开一个文件进行读操作,如果文件不存在,程序将打开一个空文件
我的答案:
A
题目得分 2
参考答案:
A
从infile文件对象读取文件的所有数据并作为一个字符串返回,使用( )。
(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
B
题目得分 2
参考答案:
B
writelines()方法将( )写入文件。
(2分)
A. 一个字符串
B. 一个字符串列表
C. 一个浮点数列表
D. 一个整数列表
我的答案:
B
题目得分 2
参考答案:
B
write()方法将( )写入文件。
(2分)
A. 一个字符串
B. 一个布尔值
C. 一个浮点数
D. 一个整数
我的答案:
A
题目得分 2
参考答案:
A
打开文件c:\scores.dat进行二进制写操作,使用( )。
(2分)
A. outfile = open(“c:\scores.dat”, “wb”)
B. outfile = open(“c:\scores.dat”, “w”)
C. outfile = open(“c:\scores.dat”, “a”)
D. outfile = open(“c:\scores.dat”, “w”)
我的答案:
A
题目得分 2
参考答案:
A
从infile文件对象读取文件的一行数据并作为一个字符串返回,使用( )。
(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
C
题目得分 2
参考答案:
C
从infile文件对象读取文件的所有行数据,使用( )。
(2分)
A. infile.read(2)
B. infile.read()
C. infile.readline()
D. infile.readlines()
我的答案:
D
题目得分 2
参考答案:
D
readlines()方法返回( )。
(2分)
A. 一个字符串
B. 一个字符串(行)列表
C. 一个浮点数列表
D. 一个整数列表
我的答案:
B
题目得分 2
参考答案:
B
( )函数可以用来检查文件f是否存在。
(2分)
A. os.path.isFile(f)
B. os.path.exists(f)
C. os.path.isfile(f)
D. os.isFile(f)
我的答案:
C
题目得分 2
参考答案:
C
打开文件c:\scores.dat进行二进制读操作,使用( )。
(2分)
A. infile = open(“c:\scores.dat”, “rb”)
B. infile = open(“c:\scores.dat”, “r”)
C. infile = open(“c:\scores.dat”, “wrb”)
D. infile =open(“c:\scores.dat”, “r”)
我的答案:
A
题目得分 2
参考答案:
A
打开文件c:\scores.txt进行读写操作,使用( )。
(2分)
A. iofile = open(“c:\scores.txt”,“r”)
B. iofile = open(“c:\scores.txt”, “w”)
C. iofile = open(“c:\scores.txt”, “ab”)
D. iofile = open(“c:\scores.txt”, “r+”)
我的答案:
D
题目得分 2
参考答案:
D
可以使用( )方法进行二进制读操作。
(2分)
A. read
B. input
C. load
D. receive
我的答案:
C
题目得分 2
参考答案:
C
调用( )方法将字符串转换成原始字节数据。
(2分)
A. encode()
B. decode()
C. convert()
D. toString()
我的答案:
A
题目得分 2
参考答案:
A
可以使用( )方法进行二进制写操作。
(2分)
A. write
B. output
C. dump
D. send
我的答案:
C
题目得分 2
参考答案:
C
调用( )方法将原始字节数据转换成字符串。(2分)
A. encode()
B. decode()
C. convert()
D. toString()
我的答案:
B
题目得分 2
参考答案:
B