import six


def text_repr(val):
    """Format values in a way that can be written as text to disk.

    Encode Unicode values as UTF-8 bytestrings (recommended for csv.writer),
    and use the str() representation of numbers.

    Args:
        val (obj): A string-able object, a `unicode` object, or `None`

    Returns:
        str: The string representation of `val`
    """

    if isinstance(val, six.text_type):
        val_text = val.encode('utf8', 'ignore')
    elif val is None:
        val_text = ''
    else:
        val_text = str(val)

    return val_text