I want to read a file with data, coded in hex format:
01ff0aa121221aff110120...etc
the files contains >100.000 such bytes, some more than 1.000.000 (they comes form DNA sequencing)
I tried the following code (and other similar):
filele=1234563
f=open('data.geno','r')
c=[]
for i in range(filele):
a=f.read(1)
b=a.encode("hex")
c.append(b)
f.close()
This gives each byte separate "aa" "01" "f1" etc, that is perfect for me!
This works fine up to (in this case) byte no 905 that happen to be "1a". I also tried the ord() function that also stopped at the same byte.
There might be a simple solution?
'rb'as your flags toopen.hexcodec was removed fromstr.encodein Py3). Try it by itself for every possible character:for c in map(chr, range(256)): print c.encode('hex'). They all work. My answer optimizes to do most of the work at the C layer (in exchange for slightly higher peak memory usage), but your code as given can't break in any way that makes sense. Please give the exact exception or misbehavior.