,

Python – Human Readable Bytes as KB, MB, GB, TB


def hbytes(num):
    for x in ['bytes','KB','MB','GB']:
        if num < 1024.0:
            return "%3.1f%s" % (num, x)
        num /= 1024.0
    return "%3.1f%s" % (num, 'TB')


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *