Francesc Alted <fal...@pytables.org> writes:

> This has been addressed in 2.2 series.  In trunk, you have:
>
> In [1]: import tables
>
> In [2]: fyle = tables.openFile("/tmp/file1.h5")
>
> In [3]: fyle2 = tables.openFile("/tmp/file1.h5",mode="a")
>
> In [4]: fyle
> Out[4]:     
> File(filename=/tmp/file1.h5, title='', mode='r', rootUEP='/', 
> filters=Filters(complevel=0, shuffle=False, fletcher32=False))                
>                                                                               
>                       
> / (RootGroup) ''                                                              
>                                           
>
> In [5]: fyle2
> Out[5]:
> File(filename=/tmp/file1.h5, title='', mode='r', rootUEP='/', 
> filters=Filters(complevel=0, shuffle=False, fletcher32=False))
> / (RootGroup) ''
>
> But, as you can see, `fyle2` is opened in read-only mode (it is basically a 
> pointer to existing `fyle` handler).  Mmh, I'm not sure whether this is good 
> practice or the second opening should fail with something like:
>
>             raise ValueError(
>                 "The file '%s' is already opened.  Please "
>                 "close it before reopening in 'a'ppend mode." % filename)
>
> What do you think is more convenient?

Umm, the current behaviour violates the principle of least surprise,
i.e. if the second call to ``openFile()`` is successful, the user
expects ``fyle2`` to be appendable, so he will be puzzled to see writes
fail with a ``FileModeError``.

The alternative behaviour explicitly exposes the limitation and avoids
the surprise.

::

  Ivan Vilata i Balaguer -- http://ivan.lovesgazpacho.net/


------------------------------------------------------------------------------
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to