title: Read a pgm file in python
body: <p>I am interested in reading a pgm file in python as a numerical file/matrix</p>
  
  <p>Right now I open the file with</p>
  
  <pre><code>f = open('/home/matthew/NCM/mdb001.pgm', 'rb')
  </code></pre>
  
  <p>When I read the first line, it looks as expected</p>
  
  <pre><code>r.readline()
  </code></pre>
  
  <p>produces</p>
  
  <pre><code>'P5\n'
  </code></pre>
  
  <p>and the next line is fine</p>
  
  <pre><code>'1024 1024\n'
  </code></pre>
  
  <p>and the next</p>
  
  <pre><code>'255\n'
  </code></pre>
  
  <p>but then I get a series of gibberish. It looks like some hex values mixed in with other stuff.</p>
  
  <p>I don't want to view the file as an image picture, I just want to see it in <a href="http://netpbm.sourceforge.net/doc/pgm.html" rel="noreferrer">this</a> format.</p>