下列代码中能够正确实现追加写入的是( )。
A: with open("d:\\python\\data.txt",'w') as f: f.write('Hello!')
B: with open("d:\\python\\data.txt",'a') as f: f.write('Hello!')
C: with open("d:\\python\\data.txt",'r+') as f: f.write('Hello!')
D: with open("d:\\python\\data.txt",'wb+') as f: f.write('Hello!')
A: with open("d:\\python\\data.txt",'w') as f: f.write('Hello!')
B: with open("d:\\python\\data.txt",'a') as f: f.write('Hello!')
C: with open("d:\\python\\data.txt",'r+') as f: f.write('Hello!')
D: with open("d:\\python\\data.txt",'wb+') as f: f.write('Hello!')
举一反三
- 若文件data.txt中有字符串“飞雪连天射白鹿”,则不能将"笑书神侠倚碧鸳"写入该字符串后面的语句是( ) A: f=open("data.txt",'a')f.write("笑书神侠倚碧鸳")f.close() B: f=open("data.txt",'w+')f.write("笑书神侠倚碧鸳")f.close() C: f=open("data.txt",'w+')f.writelines(["飞雪连天射白鹿","笑书神侠倚碧鸳"])f.close() D: f=open("data.txt",'w')f.write("飞雪连天射白鹿笑书神侠倚碧鸳")f.close()
- 执行 f = open('a.txt', 'a+') 后,通过如下哪个语句可以往a.txt中写入HELLO? A: f.write('HELLO') B: f.cout('HELLO') C: f.read('HELLO') D: f.scanf('HELLO')
- import randomf = open(‘data.txt’,‘w+’)for i in range(100000):f.write(str(random.randint(1,100)) + ‘\n’)f.seek(0)print(f.read())f.close()问:创建的data.txt文件中有多少行
- 如果从数据文件 c:\data.txt 中读取数据时,以下打开文件方式中,正确的是( ). A: Open c:\data.txt For Input As B: 1 C: Open c:\data.txt For Output As D: 1 E: Open "c:\data.txt" For Input As F: 1 G: Open "c:\data.txt" For Output As H: 1
- 下列程序的输出结果是()。f=open('out.txt','w+')f.write('Python') f.seek(0)c=f.read(2) print() f.close() A: Pyth B: Python C: Py D: th