def nice_size(size, include_bytes=False):
 niced = False
 nice_string = ('%s bytes' % size)
 try:
  nsize = Decimal(size)
  for x in ['bytes', 'KB', 'MB', 'GB']:
   if (nsize.compare(Decimal('1024.0')) == Decimal('-1')):
    nice_string = ('%3.1f %s' % (nsize, x))
    niced = True
    break
   nsize /= Decimal('1024.0')
  if (not niced):
   nice_string = ('%3.1f %s' % (nsize, 'TB'))
   niced = True
  if (include_bytes and (x != 'bytes')):
   nice_string = ('%s (%s bytes)' % (nice_string, size))
 except:
  pass
 return nice_string

def nice_size ( size , include_bytes = False ) : niced = False nice_string = ( '%s bytes' % size ) try : nsize = Decimal ( size ) for x in [ 'bytes' , 'KB' , 'MB' , 'GB' ] : if ( nsize . compare ( Decimal ( '1024.0' ) ) == Decimal ( '-1' ) ) : nice_string = ( '%3.1f %s' % ( nsize , x ) ) niced = True break nsize /= Decimal ( '1024.0' ) if ( not niced ) : nice_string = ( '%3.1f %s' % ( nsize , 'TB' ) ) niced = True if ( include_bytes and ( x != 'bytes' ) ) : nice_string = ( '%s (%s bytes)' % ( nice_string , size ) ) except : pass return nice_string
returns a readably formatted string with the size .