hex(dummy)[2:] - issue...
Tim Chase
python.list at tim.thechases.com
Wed May 6 14:13:23 EDT 2009
> I need some advice :-)
> I'm using hex(dummy)[2:] to represent a color in hexadecimal format for
> the bgcolor in an html file. dummy is the color value in RGB of course...
>
> Now, if there's an R, G or B value of zero, this command only prints one
> single 0 instead of two. What's wrong with the code?
You can try
PLACES = 2 # 6?
hex(dummy)[2:].zfill(PLACES)
Alternatively, you can output decimal numbers in HTML/CSS with
rgb(r, g, b)
such as
style="rgb(255,0,0)"
However, I recommend doing this via CSS unless you have a strong
reason to sully your HTML with style information.
-tkc
More information about the Python-list
mailing list