def int_to_var_bytes(x):
    """Converts an integer to a bitcoin variable length integer as a bytearray

    :param x: the integer to convert
    """
    if x < 253:
        return intbytes.to_bytes(x, 1)
    elif x < 65536:
        return bytearray([253]) + intbytes.to_bytes(x, 2)[::-1]
    elif x < 4294967296:
        return bytearray([254]) + intbytes.to_bytes(x, 4)[::-1]
    else:
        return bytearray([255]) + intbytes.to_bytes(x, 8)[::-1]
def int_to_var_bytes ( x ) : if x < 253 : return intbytes . to_bytes ( x , 1 ) elif x < 65536 : return bytearray ( [ 253 ] ) + intbytes . to_bytes ( x , 2 ) [ : : - 1 ] elif x < 4294967296 : return bytearray ( [ 254 ] ) + intbytes . to_bytes ( x , 4 ) [ : : - 1 ] else : return bytearray ( [ 255 ] ) + intbytes . to_bytes ( x , 8 ) [ : : - 1 ]
Converts an integer to a bitcoin variable length integer as a bytearray

    :param x: the integer to convert