def _format_value(value):

    # string value should occupies at least 8 columns, unless it is
    # a null string
    if isinstance(value, string_types):
        if value == '':
            return "''"
        else:
            exp_val_str = value.replace("'", "''")
            val_str = "'%-8s'" % exp_val_str
            return '%-20s' % val_str

    # must be before int checking since bool is also int
    elif isinstance(value, (bool, np.bool_)):
        return '%20s' % repr(value)[0]  # T or F

    elif _is_int(value):
        return '%20d' % value

    elif isinstance(value, (float, np.floating)):
        return '%20s' % _format_float(value)

    elif isinstance(value, (complex, np.complexfloating)):
        val_str = '(%s, %s)' % (_format_float(value.real),
                                _format_float(value.imag))
        return '%20s' % val_str

    elif isinstance(value, Undefined):
        return ''
    else:
        return ''
Converts a card value to its appropriate string representation as
dataset/ETHPy150Open spacetelescope/PyFITS/pyfits/card.py/_format_value