[Tutor] How can I convert a bin string to a hex string?
Rafael Sousa
rafael.sousa at netcabo.pt
Fri Oct 10 16:46:13 EDT 2003
Thanks! That's exactly what I need!
I wonder: Is there anything that Python doesn't have a module for?
----- Original Message -----
From: "Danny Yoo" <dyoo at hkn.eecs.berkeley.edu>
To: "rafael.sousa" <rafael.sousa at netcabo.pt>
Cc: <tutor at python.org>
Sent: Thursday, October 09, 2003 7:02 PM
Subject: Re: [Tutor] How can I convert a bin string to a hex string?
>
>
> On Thu, 9 Oct 2003, rafael.sousa wrote:
>
> > Such as the binary contents of a jpeg image?
> > I'm writing the code to dynamically create a RTF (Rich Text Format)
> > document. In order to insert a picture, it's recommended in the
> > specification that its contents are written in hex.
> > I read the binary content to a regular python string, but then I would
> > need to convert it to another string, this time in hex (which would
> > naturally have the double of the length of the original bin string).
>
>
> Hi Rafael,
>
>
> Ah, then the 'binascii' module should be suitable for this:
>
> http://www.python.org/doc/lib/module-binascii.html
>
> The binascii.hexlify() function should be exactly what you're looking for.
>
>
>
> Good luck!
>
>
More information about the Tutor
mailing list