Skip to content

Instantly share code, notes, and snippets.

@SEJeff
Created February 27, 2012 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SEJeff/1927621 to your computer and use it in GitHub Desktop.
Save SEJeff/1927621 to your computer and use it in GitHub Desktop.
Nifty python function for turning machine readable bytes into human readable sizes
def hr_bytes(size):
'''
This just returns the bytes in a human readable format.
'''
hr = lambda s:[(s%1024**i and "%.1f"%(s/1024.0**i) or str(s/1024**i))+x.strip() for i,x in enumerate(' KMGTPEZY') if s<1024**(i+1) or i==8][0]
return hr(size)
@SEJeff
Copy link
Author

SEJeff commented Feb 27, 2012

Credit for this gem goes to @MTecknology

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment