def _caller_symbols():
    """Global and local symbols from three calling frames back

    Thanks to Itamar Shtull-Trauring for showing how this is done."""
    try:
        raise StandardError
    except StandardError:
        fr = sys.exc_info()[2].tb_frame
        # We go back three calling frames: to __process() to
        # __init__() or __str__() to its caller.
        return (fr.f_back.f_back.f_back.f_globals,
                fr.f_back.f_back.f_back.f_locals)
Global and local symbols from three calling frames back

    Thanks to Itamar Shtull-Trauring for showing how this is done.
recipes/Python/52290_Printing_strings_embedded_variable/recipe-52290.py