def reportMemory ( k , options , field = None , isBytes = False ) : if options . pretty : return prettyMemory ( int ( k ) , field = field , isBytes = isBytes ) else : if isBytes : k /= 1024. if field is not None : return "%*dK" % ( field - 1 , k ) # -1 for the "K" else : return "%dK" % int ( k )
format a number to m or k if large python
Given k kilobytes report back the correct format as string .
def reportMemory(k, options, field=None, isBytes=False):
    """ Given k kilobytes, report back the correct format as string.
    """
    if options.pretty:
        return prettyMemory(int(k), field=field, isBytes=isBytes)
    else:
        if isBytes:
            k /= 1024.
        if field is not None:
            return "%*dK" % (field - 1, k)  # -1 for the "K"
        else:
            return "%dK" % int(k)