Quick Question

Carl J. Van Arsdall cvanarsdall at mvista.com
Thu Jun 22 16:01:48 EDT 2006


xkenneth wrote:
> 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
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list