cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How do I pass arguments/variables to notebooks?

__Databricks_Su
Contributor
 
17 REPLIES 17

Manoj12421
Valued Contributor II

You can use % run and then provide exact path of another notebook which one you want to call and for passing parameter โ€‹in Pyspark just use Variable1= 'Valuea'

Variable2= 'Valueb'

โ€‹

For scala use :

$ Vara='Valuea'

$ Varb=' Valueb'

โ€‹

โ€‹

luis_herrera
Contributor

You can use a JSON file to temporarily store the arguments that you want to use in your notebook when passing arguments/variables to it. Using json.You can define the argument list and convert it to a JSON file ().Once the argument file is created, you can open it in a notebook and use the arguments by reading the contents and converting the JSON back into a dictionary with json.loads().

https://kb.databricks.com/jobs/pass-arguments-to-a-notebook-as-a-list

luis_herrera
Contributor

To pass arguments/variables to a notebook, you can use a JSON file to temporarily store the arguments and then pass it as one argument to the notebook. After passing the JSON file to the notebook, you can parse it with json.loads(). The argument list should be defined and converted to a JSON file using json.dumps(). Once the argument file is created, you can open it inside a notebook and use the arguments by reading the contents and converting the JSON back into a dictionary using json.loads().

PS: Check #DAIS2023 talks

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group