1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| for filenames in glob.glob(os.path.join(rep_cour,"atraiter\\result\\*.txt")) :
fich_in = open(filenames, 'r')
(rep, new_name) = os.path.split(filenames)
fileModif = open(os.path.join("atraiter\\pass2", new_name), 'w')
#print fich_in
#print fileModif
#boucle les lignes
for line in fich_in :
#split la ligne en enlevant les espaces
info = re.split("\s*", line)
#si le nom est START, stoque les valeurs pour pouvoir les soustraire
if info[0] == "START" :
infoPrec = info
#si le nopm commence par BEND, modifie la ligne
elif info[0][:4] == "BEND":
#boucle les 3 chiffres
for i in range(1,4):
#la nouvelle valeur
newVal = str(float(info[i]) - float(infoPrec[i]))
#remplace l'ancienne valeur par la nouvelle
line = line.replace(info[i], newVal, 1)
#stoque les valeurs pour le prochain BEND
infoPrec = info
#ecrit la ligne dans le fichier
if line[0:6] != "/SPOOL" and line[0:14] != "WALL-THICKNESS" and line[0:6] != "FINISH" and line[0:10] != "/END-SPOOL":
fileModif.write(line)
fileModif.close()
fich_in.close() |
Partager