Link classes¶
The Link class¶
-
class
tables.link.
Link
(parentnode, name, target=None, _log=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=None, newname=None, overwrite=False, createparents=False)[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.
-
Link.
move
(newparent=None, newname=None, overwrite=False)[source]¶ Move or rename this link.
See
Node._f_move()
for a complete explanation of the arguments.
-
Link.
rename
(newname=None, overwrite=False)[source]¶ Rename this link in place.
See
Node._f_rename()
for a complete explanation of the arguments.
The SoftLink class¶
-
class
tables.link.
SoftLink
(parentnode, name, target=None, _log=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
- ::
>>> 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’))
SoftLink special methods¶
The following methods are specific for dereferrencing and representing soft links.
-
SoftLink.
__call__
()[source]¶ Dereference self.target and return the object.
Examples
>>> f=tables.open_file('data/test.h5') >>> print(f.root.link0) /link0 (SoftLink) -> /another/path >>> print(f.root.link0()) /another/path (Group) ''
-
SoftLink.
__str__
()¶ Return a short string representation of the link.
Examples
>>> f=tables.open_file('data/test.h5') >>> print(f.root.link0) /link0 (SoftLink) -> /path/to/node
The ExternalLink class¶
-
class
tables.link.
ExternalLink
(parentnode, name, target=None, _log=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 special methods¶
The following methods are specific for dereferrencing and representing external links.
-
ExternalLink.
__call__
(**kwargs)[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=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
-
ExternalLink.
__str__
()¶ Return a short string representation of the link.
Examples
>>> f=tables.open_file('data1/test1.h5') >>> print(f.root.link2) /link2 (ExternalLink) -> data2/test2.h5:/path/to/node