I\'d like to convert a hex triplet to an RGB tuple and then convert a tuple to a hex triplet.
def hex_to_int_color(v): if v[0] == '#': v = v[1:] assert(len(v) == 6) return int(v[:2], 16), int(v[2:4], 16), int(v[4:6], 16) def int_to_hex_color(v): assert(len(v) == 3) return '#%02x%02x%02x' % v