Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีที่ดีที่สุดในการรันไฟล์ Python ทั้งหมดในไดเรกทอรี

วิธีเร็วที่สุดคือใช้ loop ใน bash สร้างไฟล์ run_all_py.sh:

for f in *.py; do python "$f"; done

รันด้วย:

$ bash run_all_py.sh

บน UNIX สามารถใช้ xargs เพื่อรันแบบ parallel:

ตัวอย่าง

$ ls *.py | xargs -n 1 -P 4 python