Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- # detect 'IMG' in upper/lower case allowing for
- # zero or more spaces between the < and the 'I'
- img = '< *[iI][mM][gG] '
- # allow any character up to the 'ALT' or 'alt' before >
- alt = img + '.*[aA][lL][tT].*>'
- # open file and read it into list
- filename = raw_input('Enter a filename to search ')
- inf = open(filename,'r')
- lines = inf.readlines()
- # if the line has an IMG tag and no ALT inside
- # add our message as an HTML comment
- for i in range(len(lines)):
- if re.search(img,lines[i]) and not \
- re.search(alt,lines[i]):
- lines[i] += '<!-- PROVIDE ALT TAGS ON IMAGES! -->\n'
- # Now write the altered file and tidy up.
- inf.close()
- outf = open(filename,'w')
- outf.writelines(lines)
- outf.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement