I'd like to convert a hex triplet to an RGB tuple and then convert a tuple to a hex triplet.
>>> import struct >>> rgbstr='aabbcc' >>> struct.unpack('BBB',rgbstr.decode('hex')) (170, 187, 204)
and
>>> rgb = (50,100,150) >>> struct.pack('BBB',*rgb).encode('hex') '326496'
1.4m articles
1.4m replys
5 comments
57.0k users