I am making a find and replace script to fix some stuff on my website. I am using Python 3.3.2.
Here is my code:
import re
f = open('random.html', 'w')
strToSearch = " "
for line in f:
strToSearch += line
patFinder1 = re.compile('<td>Sermon Title</td>\
<td><audio preload="none" controls src="http://www.orlandobiblechurch.org/Audio/\d{6}ldm.mp3"></audio>\
</td>\
</tr>')
findPat1 = re.search(patFinder1, strToSearch)
findPat1 = re.findall(patFinder1, strToSearch)
for i in findPat1:
print(i)
subFound = patFinder1.sub('<td>Lord\'s Day Morning</td>\
<td><audio preload="none" controls src="http://www.orlandobiblechurch.org/Audio/\d{6}ldm.mp3"></audio>\
</td>\
</tr>', strToSearch)
print(subFound)
f.write(subFound)
f.close()
The problem is that python tells me that the file is not readable. If I changes this f = open('random.html', 'w') to f = open('random.html', 'r') to this, it says it is not writable. It makes sense why it needs both, but if I put both in, it tells me there must be exactly one read/write thing. I am positive that this is something basic, I just can't figure it out. Thanks for any help you can provide.