Get the node under where with the given name. Parameters ---------- where : str or Node This can be a path string leading to a node or a Node instance (see :ref:`NodeClassDescr`). If no name is specified, that node is returned.
(
self,
where: Node | str,
name: str | None = None,
classname: str | None = None,
)
| 1744 | return node |
| 1745 | |
| 1746 | def get_node( |
| 1747 | self, |
| 1748 | where: Node | str, |
| 1749 | name: str | None = None, |
| 1750 | classname: str | None = None, |
| 1751 | ) -> Node: |
| 1752 | """Get the node under where with the given name. |
| 1753 | |
| 1754 | Parameters |
| 1755 | ---------- |
| 1756 | where : str or Node |
| 1757 | This can be a path string leading to a node or a Node instance (see |
| 1758 | :ref:`NodeClassDescr`). If no name is specified, that node is |
| 1759 | returned. |
| 1760 | |
| 1761 | .. note:: |
| 1762 | |
| 1763 | If where is a Node instance from a different file than the one |
| 1764 | on which this function is called, the returned node will also |
| 1765 | be from that other file. |
| 1766 | |
| 1767 | name : str, optional |
| 1768 | If a name is specified, this must be a string with the name of |
| 1769 | a node under where. In this case the where argument can only |
| 1770 | lead to a Group (see :ref:`GroupClassDescr`) instance (else a |
| 1771 | TypeError is raised). The node called name under the group |
| 1772 | where is returned. |
| 1773 | classname : str, optional |
| 1774 | If the classname argument is specified, it must be the name of |
| 1775 | a class derived from Node (e.g. Table). If the node is found but it |
| 1776 | is not an instance of that class, a NoSuchNodeError is also raised. |
| 1777 | |
| 1778 | Notes |
| 1779 | ----- |
| 1780 | If the node to be returned does not exist, a NoSuchNodeError is |
| 1781 | raised. Please note that hidden nodes are also considered. |
| 1782 | |
| 1783 | """ |
| 1784 | self._check_open() |
| 1785 | |
| 1786 | if isinstance(where, Node): |
| 1787 | where._g_check_open() |
| 1788 | |
| 1789 | basepath = where._v_pathname |
| 1790 | nodepath = join_path(basepath, name or "") or "/" |
| 1791 | node = where._v_file._get_node(nodepath) |
| 1792 | elif isinstance(where, (str, np.str_)): |
| 1793 | if not where.startswith("/"): |
| 1794 | raise NameError("``where`` must start with a slash ('/')") |
| 1795 | |
| 1796 | basepath = where |
| 1797 | nodepath = join_path(basepath, name or "") or "/" |
| 1798 | node = self._get_node(nodepath) |
| 1799 | else: |
| 1800 | raise TypeError(f"``where`` must be a string or a node: {where!r}") |
| 1801 | |
| 1802 | # Finally, check whether the desired node is an instance |
| 1803 | # of the expected class. |