[Tutor] Conversion question

Tom Green xchimeras at gmail.com
Tue May 5 01:17:43 CEST 2009


First, thanks in advance for any insight on how to assist in making me a
better Python programmer.

Here is my question.  I work with a lot of sockets and most of them require
hex data.  I am usually given a string of data to send to the socket.
Example:

"414243440d0a"

Is there a way in Python to say this is a string of HEX characters like
Perl's pack?  Right now I have to take the string and add a \x to every two
values i.e. \x41\x42...

Sometimes my string values are 99+ bytes in length.  I did write a parsing
program that would basically loop thru the string and insert the \x, but I
was wondering if there was another or better way.

Again, thanks in advance for any feedback.

Mike.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090504/1ef80094/attachment-0001.htm>


More information about the Tutor mailing list