(h, _try_alt=True)
return (0, None)
Convert a hex string to colour.
    Supports inputs as #RGB, #RGBA, #RRGGBB and #RRGGBBAA.
    If a longer string is invalid, it will try lower lengths.
Convert a hex string to colour.
    Supports inputs as #RGB, #RGBA, #RRGGBB and #RRGGBBAA.
    If a longer string is invalid, it will try lower lengths.
Convert a hex string to colour . Supports inputs as #RGB #RGBA #RRGGBB and #RRGGBBAA . If a longer string is invalid it will try lower lengths .
def hex_to_colour(h, _try_alt=True):
    """Convert a hex string to colour.
    Supports inputs as #RGB, #RGBA, #RRGGBB and #RRGGBBAA.
    If a longer string is invalid, it will try lower lengths.
    """
    if h.startswith('#'):
        h = h[1:]
    h_len = len(h)
    if h_len >= 8:
        try:
            return (8, [int(h[i*2:i*2+2], 16) for i in range(4)])
        except ValueError:
            if _try_alt:
                return hex_to_colour(h[:6])
    elif h_len >= 6:
        try:
            return (6, [int(h[i*2:i*2+2], 16) for i in range(3)] + [255])
        except ValueError:
            if _try_alt:
                return hex_to_colour(h[:4])
    elif h_len >= 4:
        try:
            return (3, [16*j+j for j in (int(h[i:i+1], 16) for i in range(4))])
        except ValueError:
            if _try_alt:
                return hex_to_colour(h[:3])
    elif h_len >= 3:
        try:
            return (3, [16*j+j for j in (int(h[i:i+1], 16) for i in range(3))] + [255])
        except ValueError:
            pass
    return (0, None)
def hex_to_colour ( h , _try_alt = True ) : if h . startswith ( '#' ) : h = h [ 1 : ] h_len = len ( h ) if h_len >= 8 : try : return ( 8 , [ int ( h [ i * 2 : i * 2 + 2 ] , 16 ) for i in range ( 4 ) ] ) except ValueError : if _try_alt : return hex_to_colour ( h [ : 6 ] ) elif h_len >= 6 : try : return ( 6 , [ int ( h [ i * 2 : i * 2 + 2 ] , 16 ) for i in range ( 3 ) ] + [ 255 ] ) except ValueError : if _try_alt : return hex_to_colour ( h [ : 4 ] ) elif h_len >= 4 : try : return ( 3 , [ 16 * j + j for j in ( int ( h [ i : i + 1 ] , 16 ) for i in range ( 4 ) ) ] ) except ValueError : if _try_alt : return hex_to_colour ( h [ : 3 ] ) elif h_len >= 3 : try : return ( 3 , [ 16 * j + j for j in ( int ( h [ i : i + 1 ] , 16 ) for i in range ( 3 ) ) ] + [ 255 ] ) except ValueError : pass return ( 0 , None )