About 733 letters

About 4 minutes

#ascii

Description: Converts an object to a string (by calling its __repr__ method), with non-ASCII characters escaped. See also the repr function.

def ascii(obj):
    '''
    Converts an object to a string (by calling its `__repr__` method), with non-ASCII characters escaped

    :param obj: An object
    :return: A string returned by obj.__repr__
    '''

Example:

class Cat:
    def __repr__(self) -> str:
        return "I am a 喵喵"

cat = Cat()

print(ascii(cat))

>>> Establishing WebAssembly Runtime.

>>> Standby.

Powered by Shift.

Updated: 6/9/2025

Author: PlanC

Created: 6/9/2025