Regular expression worries
CSUIDL PROGRAMMEr
syedamjad_a at yahoo.com
Wed Oct 11 11:46:38 EDT 2006
folks
I am new to python, so excuse me if i am asking stupid questions.
I have a txt file and here are some lines of it
Document<Keyword<date:2006-08-19> Keyword<time:11:00:43>
Keyword<username:YOURBOTNICK> Keyword<data:localhost.localdomain>
Keyword<logon:localhost.localdomain
> Keyword<date:2006-08-19> Keyword<time:11:00:44> Keyword<sender:>
Keyword<receiver:> Keyword<data::+iwx> Keyword<mode::+iwx
I am writing a python program to replace the tags and word Document
with Doc.
Here is my python program
#! /usr/local/bin/python
import sys
import string
import re
def replace():
filename='/root/Desktop/project/chatlog_20060819_110043.xml.txt'
try:
fh=open(filename,'r')
except:
print 'file not opened'
sys.exit(1)
for l in
open('/root/Desktop/project/chatlog_20060819_110043.xml.txt'):
l=l.replace("Document", "DOC")
fh.close()
if __name__=="__main__":
replace()
But it does not replace Document with Doc in the txt file
Is there anything wrong i am doing
thanks
More information about the Python-list
mailing list