0

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?

  • Or - even better - be able to go from a notebook run directly to an interactive notebook with the same parameters. – Michael Grazebrook Apr 13 '22 at 18:02
  • why not define a function that takes a dictionary as input and binds the corresponding keys and values within the notebook? This way you can print the params you want from your outer notebook and directly copy-paste that dictionary into your inner notebook – C.Nivs Apr 13 '22 at 18:16
  • Like my proposed answer? Good idea. – Michael Grazebrook Apr 13 '22 at 19:36

2 Answers2

0

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.

0

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"]
Deva
  • 11
  • 5