- """
- python合并当前目录的文件.py
- """
- import os
- #如果看不懂,可搜索一下列表解析的文章看看
- #os.listdir 列出当前目录下后缀为.py的文件,迭代读取内容写入result.txt
- flist=[r for r in os.listdir(".") if os.path.splitext(r)[-1]==".py"]
- with open("result.txt","a+") as save:
- for f in flist:
- txt=open(f,encoding="utf-8").read()
- save.write(txt)
- #该片段来自于http://www.codesnippet.cn/detail/0607201614801.html
来源: http://www.codesnippet.cn/detail/0607201614801.html