>>> 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'
>>> 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'