type converion in python
Peter Hansen
peter at engcorp.com
Wed May 28 18:00:35 EDT 2003
(Please don't write HTML in Usenet posts, or on this mailing list.)
Winnie Poon wrote:
> I’m writing a socket server in python and I’m having some trouble
> converting the data received.
We're forced to ask you, why do you want to do this? Is it solely as a
learning exercise? (in which case you should probably just do a little
experiment program first, then discard the whole idea)
If it's for a real project, then I strongly suggest you learn to use
either the asyncore library, which is a standard module in Python, or
Twisted (far better idea, in most respects), or even the SocketServer
module (again, standard Python). All of these are lightyears better
for what you are trying to do than doing it "raw" as you would in C.
All that aside, if you have a string in Python, and want to treat it
as an array of 16-bit integer quantities, you probably want to look
at the standard "struct" module to do the conversion for you.
(In Python, much of the time you should first search for a module
which does the job for you, and only later consider writing it from
scratch.)
-Peter
More information about the Python-list
mailing list