Jose, how would I do this using python?
I'm looking to write a function that will take an input string 'faf0e6' and return a string 'rgb 250 240 230'. The idea is that 'faf0e6' is easy to pass as a command line arg but that the final recipient of this data, dvipng, requires the color to be in 'TeX' format. I can do this using a shell script, attached, but our Win32 users will probably appreciate the use of python ;-) 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'? -- Angus
#! /usr/bin/env python import re, sys 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) print "success!" #return texcolor def main(argv): if len(argv) != 2: print "Expected a single arg!" sys.exit(1) make_texcolor(argv[1]) if __name__ == "__main__": main(sys.argv)
color.sh
Description: application/shellscript