Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
convertSize.py
import math
def convertSize(size):
"""
Return filesize (in Bytes) in human-readable format
"""
if (size == 0):
return '0B'
units = ("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
i = int(math.floor(math.log(size,1024)))
p = math.pow(1024,i)
size = round(size/p,2)
return '{}{}'.format(size, units[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.