cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Save default language of notebook into variable dynamically

NLearn
New Contributor II

 For one of the requirements of project, I want to save default language of notebook into variable based on notebook path mentioned dynamically.

For eg: if first notebook given by user in widget is having default language as Python then variable value should set to "Python" and if notebook has been changed to Scala then variable value should to "Scala" automatically.

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @NLearn, To change the default language of a notebook in Databricks, you can select File -> Change default ce.... This will affect all the cells in the notebook that use the same language as the default one.

Based on these information, I think you can use a similar approach as in Python to get the default language of a notebook dynamically. You can use dbutils.widgets.dropdown("language", "default", [language for language in spark.catalog.listLanguages()]) to create a dropdown widget of all languages supported by Databricks. Then, you can use dbutils.widgets.select("language") to get the selected language from the widget. Finally, you can use this variable to store or retrieve the default language of the notebook.

 

I hope this helps! Let me know if you have any other questions. 😊

NLearn
New Contributor II

Hi Kaniz,

Thank you for sharing this information. Actually, in requirement, User is passing notebook path through widget which can be based on any language "Python", "SQL" and "Scala". but user is not providing information regarding language through any widget so, we have to open notebook manually to see in which language notebook has been created. 

So Is there any way that by knowing notebook path, we can get its default language and save in some variable?

 

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.