读取文件 with open('filename.txt', 'r') as f: = f.read() 写入文件 with open('filename.txt', 'w') as f: f.write('Hello, world!')