On 08/12/2010 02:36, joblack wrote:
I have two assembly data txt files, one has the structure:

0E1459D1Fh, 0AB58FAAEh, 4303E35Bh, 55FA3020h, 0E66D76ADh,
0EF434544h, ...

and the other has the structure:

53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h,
66h, ...

(I removed the dd and db with awk)

Now I want both of them in a tupple (like map1 = ( ... ) and map2 =
( ...) in my source code so I can index them..

Any idea how to give python a hint that the h at the end of the number
means it's a hex number? Or do I have to torture myself with regex to
get it right?

If you insist on not using regex (:-)) then:

>>> text = "53h, 6, 6Bh, 0D4h, 40h, 35h, 0B5h, 33h, 0AFh, 30h, 0B3h, 66h"
>>> data = [t.strip() for t in text.split(",")]
>>> data
['53h', '6', '6Bh', '0D4h', '40h', '35h', '0B5h', '33h', '0AFh', '30h', '0B3h', '66h']
>>> data = [int(d[ : -1], 16) if d[-1] == "h" else int(d) for d in data]
>>> data
[83, 6, 107, 212, 64, 53, 181, 51, 175, 48, 179, 102]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to