Issue in to_bytes in porting python 3.x to 2.7 -


i started work on python 3.4 version, dont have idea python 2.7.

this code works fine in python 3.4 , want make run python 2.7, since major project works in 2.7

s = 0b10000000000000000000001110000000000000011000000000 v = s.to_bytes(8, 'little') print(v) j = 0  k = j.to_bytes(8, 'little') print(k) cdll.func(0,6,0,v,50,k,90) 

i researched to_bytes function , got function like

def to_bytes(n, width):     b = bytearray(width)     in range(width-1, -1, -1):         b[i] = n & 0xff         n >>= 8         if n == 0:             break     return bytes(b)  s = 0b10000000000000000000001110000000000000011000000000 j = (to_bytes(s, 16)) v = 0b0 k = (to_bytes(v, 16)) cdll.func(0,6,0,j,50,k,90) 

but if use in code not working expected.is there compatible to_bytes function in 2.7 please on this.

you can use struct module in either 2.7 or 3.x convert values byte strings.

v = struct.pack('<q', s) 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -