(input)
return bytes
Convert sizes from human format to bytes (string to integer)
Convert sizes from human format to bytes (string to integer)
Convert sizes from human format to bytes ( string to integer )
def hsize_to_bytes (input):
    """ Convert sizes from human format to bytes (string to integer) """

    assert isinstance (input, str)
    m = re.match (r"^([0-9]+) *([KMGTPEZY]?)B?$", input.strip(), re.IGNORECASE)
    if not m: raise ValueError ("cannot parse: %s" % input)
    units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
    bytes = int(m.group(1)) * 1024 ** units.index(m.group(2).upper())
    return bytes
def hsize_to_bytes ( input ) : assert isinstance ( input , str ) m = re . match ( r"^([0-9]+) *([KMGTPEZY]?)B?$" , input . strip ( ) , re . IGNORECASE ) if not m : raise ValueError ( "cannot parse: %s" % input ) units = [ '' , 'K' , 'M' , 'G' , 'T' , 'P' , 'E' , 'Z' , 'Y' ] bytes = int ( m . group ( 1 ) ) * 1024 ** units . index ( m . group ( 2 ) . upper ( ) ) return bytes