读写与遍历

63.2 读写与遍历

read_text / write_text 读写文本;iterdir 列出目录。

列出 py 文件

from pathlib import Path
for f in Path('.').glob('*.py'):
    print(f.name)