Skip to content

Instantly share code, notes, and snippets.

@IamMiracleAlex
Created February 27, 2023 20:48
Show Gist options
  • Save IamMiracleAlex/1f33331f837e6228473ac6bc0a59043f to your computer and use it in GitHub Desktop.
Save IamMiracleAlex/1f33331f837e6228473ac6bc0a59043f to your computer and use it in GitHub Desktop.
Calculates storage size and returns the value
def calculate_size(size):
"""
Calculates storage size and returns the value
A single record is 1kb
"""
for x in ["KB", "MB", "GB", "TB"]:
if size < 1000.0:
return "%3.1f %s" % (size, x)
size /= 1000.0
return size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment