I wouldn't really call this a program I made, but the first two functions decide whether to open a file or not, and for each error is explained, for the third function, you put in a file and choose what you want to change and what to, I uploaded a version of this yesterday but it didn't have the .IGNORECASE to ignore if it's Capitalized or not, so yeah, i can do a lot with this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| import re
def main():
fh =open('raven.txt')
pattern = re.compile('Nevermore', re.I)
for line in fh:
if re.search(pattern, line):
print(pattern.sub('###', line), end='')
main()
def main2():
try:
for line in readlines('rotf.xt'): print(line.strip())
except IOError as e:
print('sorry no file found', e)
except ValueError as e:
print('bad filename!', e)
def readlines(filename):
if filename.endswith('.txt'):
fh = open (filename)
return fh.readlines()
else: raise ValueError('filename must end in .txt')
main2()
|