[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

char string 2 hex string

Antonio Chay

1/31/2008 10:05:00 PM

Hello!

I need to transform a string from a file into a hexadecimal
representation, for example:

"AAA" should be "414141"

With perl I do this with:

unpack("H*","AAA")

And with python I got this:

"".join([str(hex(ord(x)))[2:] for x in "AAA"])

But seems a little "weird" for me.

Is there another way?
Thanks in advance!
2 Answers

Paul Rubin

1/31/2008 10:09:00 PM

0

Antonio Chay <antonio.chay@gmail.com> writes:
> "AAA" should be "414141"

'AAA'.encode('hex')

Antonio Chay

2/1/2008 3:12:00 PM

0

On Jan 31, 7:09 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Antonio Chay <antonio.c...@gmail.com> writes:
> > "AAA" should be "414141"
>
> 'AAA'.encode('hex')

8-O
Cool stuff!
Thanks!