运行目录中的所有文件的Python [英] Run all Python files in a directory
本文介绍了运行目录中的所有文件的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是目录中运行所有Python文件的最好方法?
What is the best way to run all Python files in a directory?
python *.py
只执行一个文件。在shell脚本编写每个文件一行(或使文件),似乎累赘。我需要这二/三我有一系列的小matplotlib每个脚本创建一个PNG文件,并希望一次创建的所有图像。
only executes one file. Writing one line per file in a shell script (or make file) seems cumbersome. I need this b/c I have a series of small matplotlib scripts each creating a png file and want to create all of the images at once.
PS:我使用bash shell
PS: I'm using the bash shell.
推荐答案
bash有循环:
for f in *.py; do python "$f"; done
这篇关于运行目录中的所有文件的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文