import inspect


def getsource_if_available(obj):
    """
    Return the text of the source code for an object if available.  Otherwise,
    a print representation is returned.
    """
    try:
        return inspect.getsource(obj)
    except:
        return repr(obj)