RSS
菜单

Python 文件操作:open 模式、with、os 与 pathlib

open(path, mode):r 读/w 写/a 追加/r+ 读写;b 二进制(rb/wb);t 文本(默认);encoding='utf-8' 指定编码(写文件必带)。with open(...) as f 自动关闭。常用方法:read/readline/readlines、write、seek/tell(指针)、flush。os 模块:os.path.join/exists/makedirs/remove/rename、os.listdir、os.walk 遍历。pathlib(3.4+ 推荐):Path('a/b'),p.exists()/p.mkdir(parents=True)/p.read_text()/p.write_text()/p.glob('*.txt')/p.iterdir()——面向对象、跨平台。

下载推广海报

圈内讨论推广海报

《Python 文件操作:open 模式、with、os 与 pathlib》完整推广海报
一起交流

全部回复 0

分享经验,让问题更进一步

讨论,从你的观点开始

还没有回复,欢迎补充经验或分享不同的思路。