Skip to content

Instantly share code, notes, and snippets.

@sunzhongwei
Created November 14, 2012 02:17
Show Gist options
  • Save sunzhongwei/4069856 to your computer and use it in GitHub Desktop.
Save sunzhongwei/4069856 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ----------------------------------------
# DESCRIPTION
# ===========
# convert RGB to HTML color
# http://www.oschina.net/code/snippet_70229_2388
# ----------------------------------------
# build-in, 3rd party and my modules
def RGBToHTMLColor(rgb_tuple):
""" convert an (R, G, B) tuple to #RRGGBB """
hexcolor = '#%02x%02x%02x' % rgb_tuple
# that's it! '%02x' means zero-padded, 2-digit hex values
return hexcolor
# ----------------------------------------
# test cases
# ----------------------------------------
def run_doctest():
'''python -B <__file__> -v
'''
import doctest
doctest.testmod()
if '__main__' == __name__:
t = (79, 166, 231)
print RGBToHTMLColor((79, 166, 231))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment