# -*- coding: utf-8 -*-
import os
import subprocess
class cd:
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
if __name__ == "__main__":
path = os.listdir("./")
for i in range(len(path)):
if path[i].endswith(".py"):
continue
with cd("./"+path[i]):
subprocess.call("python main.py")
05-20
643
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)