Run all Python files in a directory

前端 未结 2 1874
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-05 11:36

What is the best way to run all Python files in a directory?

python *.py

only executes one file. Writing one line per file in a shell scrip

2条回答
  •  遥遥无期
    2020-12-05 12:05

    An alternative is to use xargs. That allows you to parallelise execution, which is useful on today's multi-core processors.

    ls *.py|xargs -n 1 -P 3 python
    

    The -n 1 makes xargs give each process only one of the arguments, while the -P 3 will make xargs run up to three processes in parallel.

提交回复
热议问题