title: How to write and append to h5 file multiple times in Python?
body: <p>I am trying to write datasets to h5 file in the following way:</p>
  
  <pre><code>fpath = 'path-to-/data.h5'
  with h5py.File(fpath,'w') as hf:
      hf.create_dataset('a', data=a)
  </code></pre>
  
  <p>Then I am appending to the file with more data in the same code:</p>
  
  <pre><code>with h5py.File(fpath,'a') as hf:
      dset = hf.create_dataset('b',(nrow,1),maxshape=(nrow,None),chunks=(nrow,1))
      for i in range(ncol):
          dset[:,-1:] = b
          if i+1 &lt; ncol:
              dset.resize(dset.shape[1]+1,axis=1)
  </code></pre>
  
  <p>I get the following error against the second operation (append):</p>
  
  <pre><code>OSError: Unable to create file (unable to open file: name = 'path-to-/data.h5', 
      errno = 2, error message = 'Aucun fichier ou dossier de ce type',
      flags = 13, o_flags = 242)
  </code></pre>
  
  <p>When I check the directory, the file <code>path-to-/data.h5</code> exists but without the appended datasets (checked with <code>list(hf.keys())</code>). </p>
  
  <p>To make all of this work, currently I am writing everything in one step and not using the <code>with</code> statement (as suggested in the question EDIT <a href="https://stackoverflow.com/questions/53838150/resizing-and-storing-dataset-in-h5-format-using-h5py-in-python">here</a>).</p>
  
  <pre><code>hf = h5py.File(fpath,'w')
  hf.create_dataset('a', data=a)
  dset = hf.create_dataset('b',(nrow,1),maxshape=(nrow,None),chunks=(nrow,1))
  for i in range(ncol):
      dset[:,-1:] = b
      if i+1 &lt; ncol:
          dset.resize(dset.shape[1]+1,axis=1)
  hf.close()
  </code></pre>
  
  <p>Here also, if I delete the written file and run the code again, it gives the same error as above and it only runs when I make a change in the file name (e.g. 'data_1.h5'). I don't understand this part as I anticipated that the operation <code>h5py.File(fpath,'w')</code> would be independent from existence or non-existence of the file.</p>
  
  <p>To summarise, the only way I found to make the code work is by using the second approach (write without append) and don't alter the file (rename or move) that is generated.</p>
  
  <p>I could not find it <a href="http://docs.h5py.org/en/latest/high/file.html" rel="nofollow noreferrer">here</a>, but is there a way to force write and append to a h5 file irrespective of it's existence or previous calls?</p>