python 运行当前目录下的所有文件
生活随笔
收集整理的這篇文章主要介紹了
python 运行当前目录下的所有文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
查看當前目錄下所有py文件(本身除外run)
import os
file_list = os.listdir(os.getcwd()) # 獲取當前目錄下所有的文件名
print(file_list)
for filename in file_list:
if os.path.isfile(filename) and filename.endswith('.py') and filename.find("run") == -1:
print(filename,'\n')
os.system('python {}'.format(filename))
import os
file_list = os.listdir(os.getcwd()) # 獲取當前目錄下所有的文件名
print(file_list)
for filename in file_list:
if os.path.isfile(filename) and filename.endswith('.py') and filename.find("run") == -1:
print(filename,'\n')
os.system('python {}'.format(filename))
轉載于:https://www.cnblogs.com/liuchunxiao83/p/11446966.html
總結
以上是生活随笔為你收集整理的python 运行当前目录下的所有文件的全部內容,希望文章能夠幫你解決所遇到的問題。