def val2str(val, format="%5.2f", na="na"):
    '''return a formatted value.

    If value does not fit format string, return "na"
    '''
    if type(val) == int:
        return format % val
    elif type(val) == float:
        return format % val

    try:
        x = format % val
    except (ValueError, __HOLE__):
        x = na
    return x
dataset/ETHPy150Open CGATOxford/cgat/CGAT/IOTools.py/val2str