Databases Reference
In-Depth Information
>>> f [ 'broken' ] = h5py . SoftLink ( '/some/nonexistent/object' )
>>> f [ 'broken' ]
KeyError: "unable to open object"
By the way, since soft links only record a path, they don't participate in the reference
counting that hard links do. So if you have a soft link /softlink pointing at an object
hard-linked at /a , if you delete the object ( del f["/a"] ) it will be destroyed and the
soft link will simply break.
You may be wondering what happens when a broken soft link ap‐
pears in items() or values() . The answer is that object None is used
as the value instead.
External Links
Starting with HDF5 1.8, there's an additional type of link in addition to the file-local
hard and soft links. External links allow you to refer to objects in other files. They're one
of the coolest features of HDF5, but one of the most troublesome to keep track of because
of their transparency.
An external link has two components: the name of a file, and then the (absolute) name
of an object within that file. Like soft links, you create them with a “marker” object, in
this case an instance of h5py.ExternalLink .
Let's create a file with a single object inside, and then link to it from another file:
>>> with h5py . File ( 'file_with_resource.hdf5' , 'w' ) as f1 :
... f1 . create_group ( 'mygroup' )
>>> f2 = h5py . File ( 'linking_file.hdf5' , 'w' )
>>> f2 [ 'linkname' ] = h5py . ExternalLink ( 'file_with_resource.hdf5' , 'mygroup' )
Like soft links, external links are transparent, in the sense that if they're not broken, we
get back the group or dataset they point to instead of some intermediate object. So if we
access the link we just created, we get a group back:
>>> grp = f2 [ 'linkname' ]
>>> grp . name
u'/mygroup'
However, if we look more closely we discover that this object resides in a different file:
>>> grp . file
<HDF5 file "file_with_resource.hdf5" (mode r+)>
>>> f2
<HDF5 file "linking_file.hdf5" (mode r+)>
Search WWH ::




Custom Search