def to_ascii(x):

    if isinstance(x, str):
        return x.encode('string_escape')
    elif isinstance(x, unicode):
        return x.encode('unicode_escape')
    else:
        raise TypeError
Convert Unicode or a string with unknown encoding into ASCII.
dataset/ETHPy150Open ralfonso/theory/theory/model/mpdutil.py/to_ascii