|
请回复您的答案^_^
-------- 问答题 --------
第 0 题的答案是:不会,如果不存在会创建文件
第 1 题的答案是:可以使用flush()方法将缓冲区的数据刷新到文件中
第 2 题的答案是:表示读取3个字符
第 3 题的答案是:一行,因为各个字符串末尾没有带换行符
第 4 题的答案是:因为print会默认输出一个换行符,与文件中的换行符叠加就会出现多一个换行的问题
第 5 题的答案是:因为对文件路径解析的时候把其中的\U解释为了转义字符,所以建议使用原始字符串或者加\的方式重新释义
第 6 题的答案是:"w"模式会覆盖掉原本文件的内容,所以需要确认文件本身为空或者文件数据不需要了
第 7 题的答案是:可以
第 8 题的答案是:指示当前文件读取/写入到的位置
第 9 题的答案是:end of file,文件末尾符
第 10 题的答案是:使用tell() 返回当前文件指针在文件对象中的位置
-------- 动动手 --------
请将第 0 题的代码写在下方:
f = open('FishC.txt', 'r')
content = f.read()
extracted = content[9:15]
f.close()
f = open('FishD.txt', 'w')
f.write(extracted)
f.close()
请将第 1 题的代码写在下方:
f = open('FishC.txt', 'a')
f.truncate(15)
f.close()
请将第 2 题的代码写在下方:
f = open('open_myself.py', 'r')
content = f.read()
print(content)
f.close()
请将第 3 题的代码写在下方:
zip_f = open("target.zip", "rb")
pic_f = open("test.jpg", "a+b")
content = zip_f.read()
pic_f.write(content)
zip_f.close()
pic_f.close()
|
|