How do i get each byte into a list
<p>I want to open a MIDI file and analyse each byte. But i am VERY unfamiliar with handeling bytes and bits. Midi's are written in hexadecimal if that does any difference.</p>

<p>What i want to do is put each byte into a list, and then make a for loop to check each one. How would i go about doing that?</p>

<p>I've come this far (which isn't very far):</p>

<pre><code># Open MIDI file
mFile = open("test.mid", 'rb')

# Checks if file is MIDI
hChunk = mFile.read(4)
if hChunk != b'MThd':
    raise ValueError('Not a MIDI file')

print(mFile.read())
</code></pre>

<p>Also if anyone has any easy to understand MIDI format explanation links, that would be appreciated! :)</p>

<p>just completed your code to scan the first 40 bytes of data. It prints the decimal value as well as the hex value using both C-like <code>%</code> formatting and more pythonic <code>format</code> method, which may be more understandable if format specification is in hex.</p>

<p>midi file has been downloaded <a href="https://en.wikipedia.org/wiki/File:MIDI_sample.mid?qsrc=3044" rel="nofollow">here</a> and saved in the directory of the script (hence the strange <code>__file__</code> stuff to compute proper dir when testing)</p>

<pre><code>import os

# Open MIDI file
mFile = open(os.path.join(os.path.dirname(__file__),"MIDI_sample.mid"), 'rb')

# Checks if file is MIDI
hChunk = mFile.read(4)
if hChunk != b'MThd':
    raise ValueError('Not a MIDI file')

contents = mFile.read()
mFile.close()

total_len = len(contents)

for i in range(0,40):
    print(contents[i],"x%02X"% contents[i],"x{:02X}".format(contents[i]))
</code></pre>

python list python-3.x byte midi