a guest Jun 19th, 2017 50 Never
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 \
- lines[i] += '<!-- PROVIDE ALT TAGS ON IMAGES! -->\n'
- # Now write the altered file and tidy up.
- outf = open(filename,'w')
RAW Paste Data