def filesizeformat(bytes, sep=' '):
    try:
        bytes = float(bytes)
    except (TypeError, ValueError, UnicodeDecodeError):
        return '0%sB' % sep

    if bytes < 1024:
        size = bytes
        template = '%.0f%sB'
    elif bytes < 1024 * 1024:
        size = bytes / 1024
        template = '%.0f%sKB'
    elif bytes < 1024 * 1024 * 1024:
        size = bytes / 1024 / 1024
        template = '%.1f%sMB'
    else:
        size = bytes / 1024 / 1024 / 1024
        template = '%.2f%sGB'
    return template % (size, sep)
Given an optional list of frames (defaults to current stack),
dataset/ETHPy150Open codeinn/vcs/vcs/utils/filesize.py/filesizeformat--crossover with--dataset/ETHPy150Open getsentry/raven-python/raven/utils/stacks.py/iter_stack_frames