Created
November 14, 2012 02:17
-
-
Save sunzhongwei/4069856 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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