python-3.x - 如何使用连续循环更改python中的目录?
问题描述
如何设置循环以连续更改目录?
import os
print(os .getcwd())
os.system('./gromacs.sh')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH002/')
print(os.getcwd())
os.system ('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH003/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH004/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH005/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH006/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH007/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH008/')
print(os.getcwd())
os.system('python gromacs.py')
os.chdir('/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH009/')
print(os.getcwd())
os.system('python gromacs.py')
解决方案
使用 for 循环遍历您要经过的所有目录?
var directory = '/home/abhi/screening/without_membrane/2_NS/MA_33_SCRENNING/KCATBH00'
var numOfIterations = 10 #Arbitrary value
for x in range(1, numOfIterations):
os.chdir(directory + str(x) + '/')
print(os.getcwd())
os.system('python gromacs.py')
推荐阅读
- matlab - 统计测试给出的结果与现实不同?
- oracle - PL/SQL:ORA-01747 错误:无效的规范 user.table.column、table.column 或列
- vba - 添加图表时触发的VBA PPT事件
- php - 如果有str_replace,有没有可能做XSS?
- eclipse - 如何通过来自 eclipse CDT 中的第三个库的类进行调试?
- python - 为什么混淆矩阵与精度不兼容?
- python-3.x - ecs的moto测试
- java - 检测到内存损坏 - 通过 JUnit 调试时发生
- uml - 将关联类添加到组合关系
- go - 上下文因超时而取消但计算未中止?