Reputation: 71
I'm calling a notebook like this:
dbutils.notebook.run(path, timeout, arguments)
where arguments is a dictionary containing many fields for the notebook's widgets.
I want to debug called notebook interactively: copy/pasting the widget parameters takes time and can cause hard-to-spot errors not done perfectly.
It would be nice to just take the arguments dictionary and use it directly. Perhaps copying it, then populating the widgets from the dictionary.
How can I do this, or something like it?
Upvotes: 0
Views: 2237
Reputation: 66
Pass the values as a json like below in the widget let it be "Filters"
{"Type":"Fruit","Item":"Apple"]
To read the json you need to make use of json library
import json
filters = dbutils.widgets.get("Filters")
jsonfilter = json.loads(filters)
Now you can access individual items by
jsonfilter["Item"]
Upvotes: 1
Reputation: 71
If we get some variables like this:
dbutils.widgets.text('myvar', '-1', '')
myvar = dbutils.widgets.get('myvar')
I can override them like this:
config = {'myvar': '42'}
import sys
module = sys.modules[__name__]
for k, v in config.items():
setattr(module, k, v)
Which means all the overriding happens in a cell I can later delete, leaving no edits in the real code.
Upvotes: 0