By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

search and replace in python. replacing content between markers

P: 8
so i have a code in python for search and replace.

fin = open(r'F:\1\xxx.txt')
fout = open(r'F:\1\xxx2.txt', "wt")
for line in fin:
fout.write( line.replace('foo', 'bar') )
fin.close()
fout.close()

and I was wondering if there was a way to tell it to replace anything between a certain set of markers. like anything between the number 1111 and 2222 if they appear in the read text file. replace the whole paragraph that is with another paragraph. my purpose for this is to be able to update code files more effectively. so say i have similar code files. and i updated a certain segment that appears in all of them. instead of going one By one editing i could write them in advance between markers like

1111

2222

3333

and then be able to update the paragraph in between. anyone has a clue how this can be done?
Sep 25 '17 #1
Share this Question
Share on Google+
1 Reply


P: 8
found this software by the way which makes it really easy if its relevant to anyone- nodesoft-searchandreaplce
Sep 26 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.