Quick Question

X

xkenneth

I want to be able to cycle through an array and print something in
hexadecimal. Such as this
thisArray = ["AF","0F","5F"]
for x in range(len(thisArray)):
print "\x" + thisArray[x]

However python chokes on the escaped identifier, how can I get around
this?

Thanks!
Regards,
Ken
 
C

Carl J. Van Arsdall

xkenneth said:
I want to be able to cycle through an array and print something in
hexadecimal. Such as this
thisArray = ["AF","0F","5F"]
for x in range(len(thisArray)):
print "\x" + thisArray[x]

However python chokes on the escaped identifier, how can I get around
this?

Thanks!
Regards,
Ken
If you have things in a list you can iterate through the list much easier:

thisArray = ["AF","0F","5F"]
for item in thisArray:
print item



In this array you store strings, so if you want to print stuff out in
hex you need to give python integers, so let's say you have a list of
integers:

thisArray = [256,512,1024]
for item in thisArray:
print "%x"%item


That will print those integers in hex.

-carl


--

Carl J. Van Arsdall
(e-mail address removed)
Build and Release
MontaVista Software
 
A

Alexis Roda

En/na xkenneth ha escrit:
I want to be able to cycle through an array and print something in
hexadecimal. Such as this
thisArray = ["AF","0F","5F"]
for x in range(len(thisArray)):
print "\x" + thisArray[x]

However python chokes on the escaped identifier, how can I get around
this?

What's the expected output?

\xAF
\x=F
\x5F ?

for x in thisArray :
print "\\x" + x


HTH
 
B

Bruno Desthuilliers

xkenneth a écrit :
I want to be able to cycle through an array and print something in
hexadecimal. Such as this
thisArray = ["AF","0F","5F"]
for x in range(len(thisArray)):
print "\x" + thisArray[x]

However python chokes on the escaped identifier, how can I get around
this?

Either by escaping the backslash:
print "\\x"
or by using a raw string:
print r"\x"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top