python struct unpack

분류없음 2009/03/30 15:25
phi = open(sys.argv[1], 'rb').read()
spec = {'header': [4, 48], 'parameter': [56, 104], 'phi': [108, -4]}

header = phi[spec['header'][0]:spec['header'][1]]
parameter = phi[spec['parameter'][0]:spec['parameter'][1]]
nphi = struct.unpack('i', phi[spec['phi'][0]:spec['phi'][0]+4])[0]/4

nclx, ncly, nclz, dcel, xbcen, ybcen, zbcen = struct.unpack('3i d 3d', header[0:44])


So, I had above code working in my laptop. And try to migrate the code to my server, and it suddenly stopped working. at the very last line. So does it work in Mac OS and not linux? But it worked in other linux machine when I tested. So, is it the my python that sucks? No it was not.

After struggling about two hours, I found following workaround:

nclx, ncly, nclz = struct.unpack('3i', header[0:12])
dcel, xbcen, ybcen, zbcen = struct.unpack('4d', header[12:44])
# what??
#nclx, ncly, nclz, dcel, xbcen, ybcen, zbcen = struct.unpack('3i d 3d', header[0:44])


which does not make sense..... odd.
tags :
Trackback 0 : Comment 0
◀ PREV : [1] : ... [14] : [15] : [16] : [17] : [18] : [19] : [20] : [21] : [22] : ... [72] : NEXT ▶