Advertisement
here2share

# chunkSize.py

Apr 8th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # chunkSize.py
  2.  
  3. def chunkSize(num):
  4.     ''' human friendly file size '''
  5.     for unit in [' bytes','k','m','g','t','p','e','z']:
  6.         b=''
  7.         if abs(num) < 1024:
  8.             if len(unit) < 2: b='b'
  9.             return "%3.1f%s%s" % (num, unit, b)
  10.         num /= 1024.0
  11.     return "%.1f%s" % (num, 'yb')
  12. #
  13.  
  14. import random
  15.  
  16. z=1
  17. while 1:
  18.     sz=chunkSize(z)
  19.     print z, 'bytes =', sz
  20.     if 'yb' in sz: break
  21.     z*=8
  22. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement