title: Read bytes of a PNG in python
body: <p>I want to read the bytes of a PNG, and modify them. I already tried this code:</p>
  
  <pre><code>import codecs
  ed = input("Would you like to encode or decode?\n(e/d)&gt; ")
  image = input("What image would you like to use?\n&gt; ")
  if(ed == 'e'):
      imagef = codecs.open(image, encoding = "hex")
      imagel = imagef.read()
      img = imagel.decode('hex')
      print(img)
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <pre><code>Would you like to encode or decode?
  (e/d)&gt; e
  What image would you like to use?
  &gt; i.png
  Traceback (most recent call last):
    File "main.py", line 7, in &lt;module&gt;
      imagel = imagef.read()
    File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py", line 700, in read
      return self.reader.read(size)
    File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/codecs.py", line 503, in read
      newchars, decodedbytes = self.decode(data, self.errors)
    File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/hex_codec.py", line 25, in decode
      return hex_decode(input, errors)
    File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/hex_codec.py", line 19, in hex_decode
      return (binascii.a2b_hex(input), len(input))
  
  binascii.Error: Non-hexadecimal digit found
  </code></pre>
  
  <p>How would I fix this?</p>