how do i get RGB from HEX?

G. Willoughby sab at NOSPAM.freeuk.com
Sat Mar 23 06:51:47 EST 2002


Thanks m8, thats great  :)

G. Willoughby

"Robin Becker" <robin at jessikat.fsnet.co.uk> wrote in message
news:WCeE3TAUC2m8Ewar at jessikat.demon.co.uk...
> In article <a7flgu$cpg$1 at newsg1.svr.pol.co.uk>, G. Willoughby
> <sab at NOSPAM.freeuk.com> writes
> >Hi,
> >    i have been trying to do this for to long now, i know there is an
easy
> >way, please somebody put me out of my misery! i need to get the RGB value
of
> >a HEX number (eg, #DCDCDC). can anyone help?
> >
> >thanks,
> >
> >G. Willoughby
> >
> >
> split into pairs after stripping the #
>
> >>> def rgb(h):
> ...     n = eval('0x'+h[1:])
> ...     return (n>>16)&0xff, (n>>8)&0xff, n&0xff
> ...
> >>> rgb('#DCDC0a')
> (220, 220, 220)
> >>> rgb('#DCDC0a')
> (220, 220, 10)
> >>>
>
> I'm sure there's probably some better way, but the above works.
> --
> Robin Becker





More information about the Python-list mailing list