一、with open() as读写文件
好处:自动调用close()方法
语法:
with open(文件名,模式) as 文件对象:文件对象.方法()
实例:
with open('test.txt', 'r') as f:print(f.read())
二、文件读写方式
参考博文:
1、https://luckylifes./article/details/107721072?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2-107721072-blog-86745391.pc_relevant_multi_platform_whitelistv1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2-107721072-blog-86745391.pc_relevant_multi_platform_whitelistv1&utm_relevant_index=5
2、/xrinosvip/article/details/8844?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-8844-blog-107721072.pc_relevant_downloadblacklistv1&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1-8844-blog-107721072.pc_relevant_downloadblacklistv1&utm_relevant_index=1