Abstract base class for all PyTables links.
A link is a node that refers to another node. The Link class inherits from Node class and the links that inherits from Link are SoftLink and ExternalLink. There is not a HardLink subclass because hard links behave like a regular Group or Leaf. Contrarily to other nodes, links cannot have HDF5 attributes. This is an HDF5 library limitation that might be solved in future releases.
See Using links for more convenient access to nodes for a small tutorial on how to work with links.
Link attributes
The path string to the pointed node.
The following methods are useful for copying, moving, renaming and removing links.
Copy this link and return the new one.
See Node._f_copy() for a complete explanation of the arguments. Please note that there is no recursive flag since links do not have child nodes.
Move or rename this link.
See Node._f_move() for a complete explanation of the arguments.
Rename this link in place.
See Node._f_rename() for a complete explanation of the arguments.
Represents a soft link (aka symbolic link).
A soft link is a reference to another node in the same file hierarchy. Provided that the target node exists, its attributes and methods can be accessed directly from the softlink using the normal . syntax.
Softlinks also have the following public methods/attributes:
- target
- dereference()
- copy()
- move()
- remove()
- rename()
- is_dangling()
Note that these will override any correspondingly named methods/attributes of the target node.
For backwards compatibility, it is also possible to obtain the target node via the __call__() special method (this action is called dereferencing; see below)
Examples
>>> f = tables.open_file('/tmp/test_softlink.h5', 'w')
>>> a = f.create_array('/', 'A', np.arange(10))
>>> link_a = f.create_soft_link('/', 'link_A', target='/A')
# transparent read/write access to a softlinked node >>> link_a[0] = -1 >>> print(link_a[:], link_a.dtype) (array([-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]), dtype(‘int64’))
# dereferencing a softlink using the __call__() method >>> print(link_a() is a) True
# SoftLink.remove() overrides Array.remove() >>> link_a.remove() >>> print(link_a) <closed tables.link.SoftLink at 0x7febe97186e0> >>> print(a[:], a.dtype) (array([-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]), dtype(‘int64’))
The following methods are specific for dereferrencing and representing soft links.
Represents an external link.
An external link is a reference to a node in another file. Getting access to the pointed node (this action is called dereferencing) is done via the __call__() special method (see below).
ExternalLink attributes
The external file handler, if the link has been dereferenced. In case the link has not been dereferenced yet, its value is None.
The following methods are specific for dereferrencing and representing external links.
Dereference self.target and return the object.
You can pass all the arguments supported by the open_file() function (except filename, of course) so as to open the referenced external file.
Examples
>>> f=tables.open_file('data1/test1.h5')
>>> print(f.root.link2)
/link2 (ExternalLink) -> data2/test2.h5:/path/to/node
>>> plink2 = f.root.link2('a') # open in 'a'ppend mode
>>> print(plink2)
/path/to/node (Group) ''
>>> print(plink2._v_filename)
'data2/test2.h5' # belongs to referenced file