【发布时间】:2019-06-21 10:12:12
【问题描述】:
我正在尝试运行多个实验,它们位于不同的文件夹中。我想将结果保存在主文件夹中。像这样的:
主文件夹
- Main_run_file.py
- Results.txt
- 实验_1
- Run_file.py
- 实验_2
- Run_file.py
- 实验_3
- Run_file.py
我已经尝试过以下代码:
import os
mydir = os.getcwd() # would be the MAIN folder
mydir_tmp = mydir + "\Experiment_1 - 40kmh" # add the first experiment folder name
mydir_new = os.chdir(mydir_tmp) # change the current working directory
mydir = os.getcwd() # set the main directory again
import Run_file
mydir = os.getcwd() # would be the MAIN folder
mydir_tmp = mydir + "/Experiment_1 - 60kmh" # add the second experiment folder name
mydir_new = os.chdir(mydir_tmp) # change the current working directory
mydir = os.getcwd() # set the main directory again
import Run_file
但是,这只运行第一个 Run_file 而不是第二个。有人可以帮我解决这个问题吗?
【问题讨论】:
-
嘿,看看stackoverflow.com/questions/21963270/…,他也有同样的问题
标签: python-3.x