I am trying to use if statements to check for the presence of a particular string which also happens to be with the same file name. However, I have come across two strings that have common characters and I would like to strictly not check for duplicates. Here is the part of my code. I have two files named p_rgh_0 and h_0.
for path, dirs, files in os.walk(logsDir, topdown=False):
for lf in sorted(files):
if (plot_pressure or plot_all):
if any( (filename in lf) for filename in ('p_0', 'p_rgh_0') ):
logFile = os.path.join(path, lf)
data = np.loadtxt(logFile)
time, value = data[:,0], data[:,1]
(time, value, lf) = pressure(time, value, lf)
if (plot_enthalpy):
if any( (filename in lf) for filename in ('h_0') ):
print lf
logFile = os.path.join(path, lf)
data = np.loadtxt(logFile)
time, value = data[:,0], data[:,1]
(time, value, lf) = enthalpy(time, value, lf)
Now since h_0 is a common string, both files are being processed in the second if statement where I check exclusively only for h_0. The print lf prints both the files, however it should be only h_0. Is there a way to eliminate this behaviour and only check for h_0?
Aucun commentaire:
Enregistrer un commentaire