Created
February 27, 2012 22:35
-
-
Save SEJeff/1927621 to your computer and use it in GitHub Desktop.
Nifty python function for turning machine readable bytes into human readable sizes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credit for this gem goes to @MTecknology