Link classes¶
The Link class¶
- class tables.link.Link(parentnode: Group, name: str, target: str | None = None, _log: bool = False)[source]¶
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
- target¶
The path string to the pointed node.
Link instance variables¶
- Link._v_attrs¶
A NoAttrs instance replacing the typical AttributeSet instance of other node objects. The purpose of NoAttrs is to make clear that HDF5 attributes are not supported in link nodes.
Link methods¶
The following methods are useful for copying, moving, renaming and removing links.
- Link.copy(newparent: Group | None = None, newname: str | None = None, overwrite: bool = False, createparents: bool = False) Link [source]¶
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.
The SoftLink class¶
- class tables.link.SoftLink(parentnode: Group, name: str, target: str | None = None, _log: bool = False)[source]¶
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
>>> import numpy as np >>> f = tb.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 >>> 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 >>> link_a() is a True # SoftLink.remove() overrides Array.remove() >>> link_a.remove() >>> print(link_a) <closed tables.link.SoftLink at ...> >>> a[:], a.dtype (array([-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]), dtype('int64')) >>> f.close()
SoftLink special methods¶
The following methods are specific for dereferencing and representing soft links.
The ExternalLink class¶
- class tables.link.ExternalLink(parentnode: Group, name: str, target: str | None = None, _log: bool = False)[source]¶
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
- extfile¶
The external file handler, if the link has been dereferenced. In case the link has not been dereferenced yet, its value is None.
ExternalLink methods¶
ExternalLink special methods¶
The following methods are specific for dereferencing and representing external links.
- ExternalLink.__call__(**kwargs) Node [source]¶
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 = tb.open_file('tables/tests/elink.h5') >>> f.root.pep.pep2 /pep/pep2 (ExternalLink) -> elink2.h5:/pep >>> pep2 = f.root.pep.pep2(mode='r') # open in 'r'ead mode >>> print(pep2) /pep (Group) '' >>> pep2._v_file.filename # belongs to referenced file 'tables/tests/elink2.h5' >>> f.close()