Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an int to a CSS colour [duplicate]

Tags:

python

css

Possible Duplicate:
RGB Int to RGB - Python

Using Python I need to convert an int to a six digit hex that I can use as a background colour in CSS. Any ideas how to do that?

The int is a primary key of a model in Django.

like image 471
Neil Avatar asked Oct 04 '11 16:10

Neil


1 Answers

Convert an int to a 6-digit hex:

In [10]: '{0:06X}'.format(16746513)
Out[10]: 'FF8811'

Check that the hex is equivalent to the int:

In [9]: int('FF8811',16)
Out[9]: 16746513
like image 61
unutbu Avatar answered Nov 03 '22 01:11

unutbu