1.1写入空文件 若将文本写入文件,在调用open()时候需要提供另外一个实参,告诉Python你要写入打开的文件 file_path = 'txt\MyFavoriteFruit.txt' with open(file_path,'w') as file_object: file_object.write('I like appple.') 在这个实例中,调用open()提供了两个实参,第一个实参是要打开文件的路径与名称,第二个实参('w')告诉Python,我们将要以写的方式打开这个文件 r…
<Python编程:从入门到实践>读书笔记 1.读取文件并且对文件内容进行打印有三种方式: with open('test.txt') as fo: for lins in fo: print(lins.rstrip()) with open('test.txt') as fo: lines=fo.read() print(lines.rstrip()) with open('test.txt') as fo2: lt=fo2.readlines() for l in lt: print(l.…