Created
November 28, 2012 19:11
-
-
Save nulltier/4163377 to your computer and use it in GitHub Desktop.
return string with human readable filesize if you give to this filesize in bytes
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 nice_size(size): | |
if size >= 1073741824: | |
postfix = " Gb." | |
divisioner = 1073741824 | |
elif 1048576 <= size < 1073741824: | |
postfix = " Mb." | |
divisioner = 1048576 | |
elif 1024 <= size < 1048576: | |
postfix = " Kb." | |
divisioner = 1024 | |
else: | |
postfix = " b." | |
divisioner = 1 | |
return str(round(size/divisioner, 2))+postfix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment