1 列出当前目录下所有py文件 l = [x for x in os.listdir('.') if os.path.isfile(x) and os.path.splitext(x)[1] == '.py' ] print(l)