[Tutor] Mad Villain Seeks Source Review.
Tesla Coil
tescoil@irtc.net
Mon, 20 Aug 2001 19:50:08 -0500
Phase One of My Diabolical Plan to Reduce the
World Wide Web to 256 Grayscale seems to have
been delayed...
import re
def namedict():
namedcolors = {'maroon' : '262626',
'green' : '4b4b4b',
'red' : '4c4c4c',
'navy' : '0e0e0e',
'purple' : '343434',
'lime' : '969696',
'blue' : '1c1c1c',
'magenta' : '686868',
'olive' : '717171',
'yellow' : 'e2e2e2',
'teal' : '595959',
'cyan' : 'b2b2b2',}
return namedcolors
def namerepl( match ):
# Adjusts various forms that may be taken
# by a match in the following function so
# as to return the dictionary value.
# Works.
namedcolors = namedict()
match = match.lower()
catch =""
for sstr in match:
if sstr.isalpha():
catch = catch+sstr
return namedcolors[catch]
def firstpass(line):
# Reduce dictionary keys into a regex and
# substitute using preceding function.
# Attribute Error: lower. Hmph. Now I'll
# have to settle for hijacking a spacecraft.
namedcolors = namedict()
colors = namedcolors.keys()
crush = lambda x,y: x+'|'+ y
colorsearch = reduce(crush, colors)
colorsearch = '[=][\s]?['+colorsearch+']'
colorsearch = re.compile(colorsearch, re.I)
line = re.sub(colorsearch, namerepl, line)
return line
teststring = "<BODY BGCOLOR='Magenta'TEXT= Yellow>"
firstpass(teststring)
---
James Bond Villain Personality Test:
http://www.physics.usyd.edu.au/~mar/villain.html