def fmt_bytes(num):
    """Returns a formatted string of num bytes."""
    for units in ['bytes', 'KB', 'MB', 'GB', 'TB']:
        if num < 1024.0:
            return "{:3.1f} {}".format(num, units)
        num /= 1024.0
    return "{:3.1f} PB".format(num)