On Tue, Dec 7, 2010 at 6:36 PM, joblack <tobias.ko...@gmail.com> 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?
No regex necessary whatsoever: # will be inefficient if file is huge f = open("path/to/assembly/file/1") content = f.read() f.close() map1 = [int(hexnum[:-1], 16) for hexnum content.split(", ")] # do same thing for 2nd file Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list