my first socket !

Andrew Bennetts andrew-pythonlist at puzzling.org
Tue Feb 18 05:14:41 EST 2003


On Tue, Feb 18, 2003 at 03:23:52AM -0600, Ian Bicking wrote:
> On Tue, 2003-02-18 at 03:15, Franck Bui-Huu wrote:
> > I'm currently trying to receive data from a socket with
> > data = mysock.recv(LENGTH)
> > the fisrt byte of data is the length of data to receive.
> > If I print the length I get : print data[0] -> "\x04"
> > How can I "cast" it in order to handle it as an int whose value is 4 ?
> 
> ord("\x04") == 4

And for larger values, e.g. 2-byte or 4-byte ints, you'll need the struct
module.

-Andrew.






More information about the Python-list mailing list