LQ Newbie
Registered: May 2009
Posts: 1
Rep:
|
Python: replacing strings in a file
I am trying to write a program that contains a loop that replaces file names in a text file with names from a set list that I have. It fails to run and I was hoping somebody could tell me why and/or figure out how to get it working.
:::::::::::::::::::::::::::::::::::::::::::
import string, sys, os, re, fileinput
i = ['zeta21000.nc','zeta21001.nc','zeta21002.nc','zeta21003.nc','zeta21004.nc','zeta21005.nc','zeta21006 .nc','zeta21007.nc','zeta21008.nc','zeta21009.nc','zeta21010.nc','zeta21011.nc','zeta21012.nc','zeta 21013.nc','zeta21014.nc','zeta21015.nc','zeta21016.nc','zeta21017.nc','zeta21018.nc','zeta21019.nc', 'zeta21020.nc','zeta21021.nc','zeta21022.nc','zeta21023.nc','zeta21024.nc','zeta21025.nc']
j =['zeta2Em007','4Em007','8_00Em007','1_60Em006','3_20Em006','6_40Em006','1_28Em005','2_56Em005','5_12E m005','1_02Em004','2_05Em004','4_10Em004','8_19Em004','1_64Em003','3_28Em003','6_55Em003','1_31Em002 ','2_62Em002','5_24Em002','1_05Em001','2_10Em001','4_19Em001','8_39Em001','1_68E000','3_36E000','6_7 1E000']
o = open("ensight_command","w")
data = open("ensight_command").read()
for x in range(0,26)
os.system("ensight82 -p ensight_command")
o.write( re.sub(i[x],i[x+1],data))
o.write( re.sub(j[x],j[x+1],data))
#ensightfile = ensightfile.replace(i[x], i[x+1])
#ensightfile = ensightfile.replace(j[x], j[x+1])
o.close()
Last edited by tonya11en; 05-19-2009 at 11:16 AM.
|