cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
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
New Contributor III
New Contributor III

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
New Contributor III
New Contributor III

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

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.