Replace Pattern

Sorin Marti mas at
Mon Feb 9 08:45:51 CET 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
        fi = open('test.sql', 'r')
        while fi.readline():
            line = fi.readline();
except IOError:
        print 'Can\'t open file for reading.'

Thanks for any help.

More information about the Python-list mailing list