How to read binary files as hex in Python?
<p>I want to read a file with data, coded in hex format:</p>

<pre><code>01ff0aa121221aff110120...etc
</code></pre>

<p>the files contains >100.000 such bytes, some more than 1.000.000 (they comes form DNA sequencing)</p>

<p>I tried the following code (and other similar):</p>

<pre><code>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()
</code></pre>

<p>This gives each byte separate "aa" "01" "f1" etc, that is perfect for me!</p>

<p>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.</p>

<p>There might be a simple solution?</p>