Apr posted 21 Apr 2009 and tagged python
def pretty_filesize(bytes):
if bytes >= 1073741824:
return str(bytes / 1024 / 1024 / 1024) + ' GB'
elif bytes >= 1048576:
return str(bytes / 1024 / 1024) + ' MB'
elif bytes >= 1024:
return str(bytes / 1024) + ' KB'
elif bytes < 1024:
return str(bytes) + ' bytes'
Pop out
1 2 3 4 5 6 7 8 9 | def pretty_filesize(bytes): if bytes >= 1073741824: return str(bytes / 1024 / 1024 / 1024) + ' GB' elif bytes >= 1048576: return str(bytes / 1024 / 1024) + ' MB' elif bytes >= 1024: return str(bytes / 1024) + ' KB' elif bytes < 1024: return str(bytes) + ' bytes' |
Converted from a similar VBasic function