Angus Leeming wrote: > I've started writing the equivalent in python (also attached), but > wonder if there is a simple way of extracting a substring 'fa' and > converting it to the equivalent decimal number '250'?
Ok, got it. #! /usr/bin/env python import re, sys from string import atoi hexcolor_re = re.compile("^[0-9a-fA-F]{6}$") def make_texcolor(hexcolor): # Test that the input string contains 6 hexadecimal chars if not hexcolor_re.match(hexcolor): print "Cannot convert '%s'" %(hexcolor) sys.exit(1) red = atoi(hexcolor[0:2], 16) green = atoi(hexcolor[2:4], 16) blue = atoi(hexcolor[4:6], 16) return "rgb %d %d %d" % (red, green, blue) def main(argv): if len(argv) != 2: print "Expected a single arg!" sys.exit(1) texcolor = make_texcolor(argv[1]) print "texcolor is ", texcolor if __name__ == "__main__": main(sys.argv) -- Angus