title: str to byte object for further use in Matlab
body: <p>I'm working with old python 2.7 code including some functions. I'm fairly new to programming and only understand some parts of it. My current problem centers around the following function:</p>
  <pre><code>def create_file(self):
      self._f = h5py.File(self.filename,'a',userblock_size=512)
      self._f.close()
      userblock_data = 'MATLAB 7.3 MAT-file, Platform: PCWIN64, Created on: %s HDF5 schema 1.00 .'%time.strftime('%a %b %d %H:%M:%S %Y')
      while len(userblock_data)&lt; 116:
          userblock_data += ' '
      userblock_data += chr(0)*9
      userblock_data += 'IM';
      with io.open(self.filename,'rb+') as f:
          f.write('userblock_data')
      self.reopen()
  </code></pre>
  <p>This raises a type error:
  <em>Expected type 'bytes' (matched generic type 'AnyStr'), got 'str' instead</em></p>
  <p>What I tried so far:</p>
  <pre><code>with io.open(self.filename,'rb+') as f:
      f.write(b'userblock_data')
  </code></pre>
  <p>This resolves the error but leads to problems further down in the code where data is being written into a h5-file for further use in Matlab.
  I'm thankful for any help you can provide</p>