Change the default language for databricks notebook

Viewed 2571

I have a Scala notebook, but now I want the default programming language for a new cell to be Python instead. Is it possible to change the notebook in that way (preferably, in a way that doesn't require manual changing of each of the existing cells)? Thanks

2 Answers

Note: You can override the primary language by specifying the language magic command % at the beginning of a cell.

The supported magic commands are: %python, %r, %scala, and %sql.

enter image description here

Note: When you invoke a language magic command, the command is dispatched to the REPL in the execution context for the notebook. Variables defined in one language (and hence in the REPL for that language) are not available in the REPL of another language. REPLs can share state only through external resources such as files in DBFS or objects in blob storage.

Additionally:

%sh

Allows you to execute shell code in your notebook. Add the -e option in order to fail the cell (and subsequently a job or a run all command) if the shell command has a non-zero exit status.

%fs

Allows you to use dbutils filesystem commands. For more information, see Access DBFS with dbutils.

%md

Allows you to include various types of documentation, including text, images, and mathematical formulas and equations.

For more details, refer "Azure Databricks - Mix Languages".

Hope this helps.

In a Scala notebook, use the magic character (%) to use a different programming language in the same notebook:

Cell 1 (Scala):

val k = "hello"

Cell 2 (change to python)

%python
print("hello")
Related