pytyon 文件的读写操作

import os
a = [x for x in os.listdir('.') if os.path.isdir(x)]
print(a)

 这段代码的结果是输出当前目录下的全部子目录(文件夹名字)

import os
a = [x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1]=='.py']
print(a)

这段代码运行的结果是输出当前目录下的全部 .py格式的文件 

Time Will Tell
原文地址:https://www.cnblogs.com/wangzaixue/p/13627222.html