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格式的文件 

 

posted @ 2020-09-07 15:34  在学同学  阅读(121)  评论(0编辑  收藏  举报