Hello all,

query 1) How should i overwrite the input file
I want to open 5 files one by one, do some operation on the lines and write
the modified lines on the same file (overwritting). Can some please tell me
how to do it.

pat1=" R"
pat2="U5"
pat3="A3"
from sys import argv
files=argv[1:]
for names in files:
        out=open(names + '_new','w')  # Here i creat new files to write the
content which i dnt want
        for line in open(names):
                if pat1 in line:
                        line=line.replace(pat1,"  ")
                if pat2 in line:
                        line=line.replace(pat2,"U ")
                if pat3 in line:
                        line=line.replace(pat3,"A ")
                out.write(line)

query 2) How should I use wild cards to open files in python. Say I have
files with names *.dat  in a directory, i want the program to open every
file with extension .dat and do the process.

Thanks in advance,
Bala
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to