Replace Pattern

Sorin Marti mas at semafor.ch
Mon Feb 9 02:45:51 EST 2004


Hello all,

I am quite new to python and want to do the following:

- open a file (done)
- read each line (done)
- search a pattern in the file and replace it
- write the new file

I want to replace the date. example: 
INSERT INTO organization VALUES ('Brussels','Brabant','23 10 1954');

should be:
INSERT INTO organization VALUES ('Brussels','Brabant','1954-10-24');

What i've done:

import os,sys
try:
        fi = open('test.sql', 'r')
        while fi.readline():
            line = fi.readline();
        
except IOError:
        print 'Can\'t open file for reading.'
        sys.exit(0)

Thanks for any help.



More information about the Python-list mailing list