如何获取当前笔记本的完整路径How to get the full path to the current notebook

本文介绍如何获取当前笔记本的完整路径。This article explains how to get full path to the current notebook.

ScalaScala

要获取 Scala 单元格中的完整路径,请在单元格中运行以下命令:To get the full path in a Scala cell, run the following command in a cell:

%scala
dbutils.notebook.getContext.notebookPath

PythonPython

要使用 Python 获取完整路径,必须获取路径并将其保存到 Scala 单元格内的小组件中,并在 Python 单元格中读取它。To get the full path using Python, you have to get the path and save it into a widget in a Scala cell and read it in a Python cell.

  1. 将值保存到 Scala 单元格内的小组件中。Save the value into a widget from Scala cell.

    %scala
    dbutils.widgets.text("notebook", dbutils.notebook.getContext().notebookPath.get)
    
  2. 从 Python 单元格中访问小组件值。Access the widget value from Python cell.

    %python
    dbutils.widgets.get("notebook")