Re: how to convert from network to host byte order

2009-03-05 Thread Mark Tolonen
"Evan" wrote in message news:79582a34-5d0b-49b2-8c1e-4139324ff...@b38g2000prf.googlegroups.com... Hello ~ I'm new with python, what my problem is, I have a binary file, I want to read first 2 bytes and convert it to host byte order, then write it to another file. There is a piece of infor

Re: how to convert from network to host byte order

2009-03-05 Thread Evan
On Mar 5, 9:50 pm, Philipp Hagemeister wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA512 > > Evan wrote: > >>> inp='\x04\x00' > >>> out = socket.ntohs(struct.unpack('H',inp[:2])[0])) > > Traceback (most recent call last): > >   File "", line 1, in > > TypeError: argument 1 must be string

Re: how to convert from network to host byte order

2009-03-05 Thread Philipp Hagemeister
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 Evan wrote: >>> inp='\x04\x00' >>> out = socket.ntohs(struct.unpack('H',inp[:2])[0])) > Traceback (most recent call last): > File "", line 1, in > TypeError: argument 1 must be string or read-only buffer, not int Your approach is nearly right. Fi

Re: how to convert from network to host byte order

2009-03-05 Thread Joe Riopel
On Thu, Mar 5, 2009 at 7:26 AM, Evan wrote: > Hello ~ > > I'm new with python,  what my problem is, I have a binary file, I want > to read first 2 bytes and convert it to host byte order, then write it > to another file. Have you checked out socket.htons, socket.ntohs, etc ? -- http://mail.python

Re: how to convert from network to host byte order

2009-03-05 Thread Peter Otten
Evan wrote: > Hello ~ > > I'm new with python, what my problem is, I have a binary file, I want > to read first 2 bytes and convert it to host byte order, then write it > to another file. > > I try to use 'socket' and 'struct', but somehow i can not get it > working fine: > > for example, tota

how to convert from network to host byte order

2009-03-05 Thread Evan
Hello ~ I'm new with python, what my problem is, I have a binary file, I want to read first 2 bytes and convert it to host byte order, then write it to another file. I try to use 'socket' and 'struct', but somehow i can not get it working fine: for example, totally I'm not sure if my steps is c