"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
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
-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
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
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
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