my first socket!
Nagy László
nagylzs at freemail.hu
Tue Feb 18 04:31:59 EST 2003
> 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 ?
>
> thanks
>
You can use the 'ord' and 'chr' functions to convert between a character
and its code.
They are using 8bit integers in range(256). If you want to send bigger
numbers you
can either
1. Create your own conversion function (e.g. send more digits with
radix 256)
2. Use the Pickle or cPickle to temporary convert the object into a
string
Laci 1.0
More information about the Python-list
mailing list