0

I am trying to create a widget button that will collect the values of other widgets and then use %run to execute another notebook with those values. I am using %store to pass the values but it does not recognize the python variable with the value to pass and gives an error.

import ipywidgets as widgets
from IPython import get_ipython
ipython = get_ipython()

def on_button_clicked(_):
    path=srch_loc.value
    with out:            
        path= srch_loc.value #returns the value typed into widget srch_loc
        print('Something happens!')
        print(path)
        ipython.magic("store path")

button.on_click(on_button_clicked)

When I click the button these are the results:

Something happens!
/san-data/users/$USER/
UsageError: Unknown variable 'path'

The print function recognizes path as a variable but the next line of code doesnt

I expect to not get an unknown variable message and if I run %store to see path listed with the correct value from srch_loc.value

Alex Brown
  • 51
  • 3

1 Answers1

0

Your path variable is local to your function. The IPython magic tries to access variables defined by the notebook code, which has a different scope.

Roland Weber
  • 3,395
  • 12
  • 26
  • Thanks for the reply Roland. If I add a `return path` at the end of the function shouldn't that put it in the same scope as the IPython magic? – Alex Brown Jul 22 '19 at 13:36