def pretty_file_size(size, use_decimal=False, **kwargs):
 try:
  size = max(float(size), 0.0)
 except (ValueError, TypeError):
  size = 0.0
 remaining_size = size
 units = kwargs.pop(u'units', [u'B', u'KB', u'MB', u'GB', u'TB', u'PB'])
 block = (1024.0 if (not use_decimal) else 1000.0)
 for unit in units:
  if (remaining_size < block):
   return u'{0:3.2f} {1}'.format(remaining_size, unit)
  remaining_size /= block
 return size

def pretty_file_size ( size , use_decimal = False , ** kwargs ) : try : size = max ( float ( size ) , 0.0 ) except ( ValueError , TypeError ) : size = 0.0 remaining_size = size units = kwargs . pop ( u'units' , [ u'B' , u'KB' , u'MB' , u'GB' , u'TB' , u'PB' ] ) block = ( 1024.0 if ( not use_decimal ) else 1000.0 ) for unit in units : if ( remaining_size < block ) : return u'{0:3.2f} {1}' . format ( remaining_size , unit ) remaining_size /= block return size
return a human readable representation of the provided size .