运行 一系列输入文件名的程序

Running a programme over a series of input file names

我有一个程序需要 运行 处理一堆不同的输入文件。我在下面包含了这段代码的快照。但是,对于每次迭代,我取消注释我想要的输入文件,并在下一个输入文件必须是 运行 时再次注释掉它。反正有自动化吗?就像写一个脚本文件,它将在每个指定的输入文件上执行 python 程序?

import matplotlib.pyplot as plt
import numpy as np
import sys
import pydicom # Importing DICOM package 
import csv
import os,string
import pandas as pd


from pyctpatientimagenoise import CTPatientImageNoise


#PathDicom = "./Images/AbdPel Low Dose 3.82 mGy - 192.37 mGy cm/1.2.840.113619.2.437.3.3104443552.660.1564558828.49/"

#------------SET of input files <comment out all others except the 1 input file you want to run the prog on>-----------------------

PathDicom = "./Images/DUKEcases/TCGA-DD-A39X/05-08-1994-CT ABDOMEN wow-06316/"

#PathDicom = "./Images/DUKEcases/TCGA-DD-A11C/05-27-1999-Abdomen120LiverBiPhase Adult-61415/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A11C/10-28-1998-Thorax04ChestBiphaseLiverPanc Adult-45922/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A39V/03-08-1994-CT ABDOMEN w  PELVIS w-44494/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A39V/12-29-1993-CT ABDOMEN wow PELVIS w-26981/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A39Y/09-16-1994-CT CHEST w-40434/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A39Y/10-06-1994-CT ABDOMEN w  PELVIS w-56041/"
#PathDicom = "./Images/DUKEcases/TCGA-DD-A113/01-02-1999-Abdomen020APRoutineAbdomenPelvis/"


Examname = []
ImageType=[]


filepaths = ['foo.bar','foo.baz','foo.bmp']
for filepath in filepaths:
    do_thing()

我建议多读一点 Python 的基础知识。它会在漫长的 运行.

中为您节省时间

运行脚本:

import subprocess

path_dicom = [
"./Images/DUKEcases/TCGA-DD-A11C/05-27-1999-Abdomen120LiverBiPhase Adult-61415/"
"./Images/DUKEcases/TCGA-DD-A113/01-02-1999-Abdomen020APRoutineAbdomenPelvis/"
 ....
]


for file_path in path_dicom:
     process = subprocess.Popen(args=['python', 'process.py', file_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)

     output, error = process.communicate()
     print(process.returncode)

文件处理脚本:

....
from pyctpatientimagenoise import CTPatientImageNoise

if len(sys.argv) < 2:
    print("Usage python process.py [file_path]")
    sys.exit(-1)

PathDicom = sys.argv[1]

Examname = []
ImageType = []