Created
October 23, 2014 01:06
-
-
Save kindy/01fe43add3f5d6a2d904 to your computer and use it in GitHub Desktop.
Quick & dirty human format of size
This file contains hidden or 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 human_size(size): | |
import re | |
def sub(m): | |
return '%s.%s%s' % (m.group(1), m.group(2)[:2], 'BKMGT'[len(m.group(2))/3]) | |
return re.sub(r'^(\d{1,3})((?:\d\d\d){1,4})$', sub, str(size)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment