0

For example, I define my own function "f":

def f(x):
    return x 

and I want to make it interactable, so I wrote another function "F":

from ipywidgets import interact
def F():
    interact(f,x=10)

but it didn't work. Any ideas about how I can adjust my code?

JackeyOL
  • 313
  • 2
  • 16

1 Answers1

1

Make sure your calling your function

def f(x):
    return x

def F():
    interact(f, x=10)

F()

will work. Since f is defined in a separate file

from MyFunctions import f

interact(f, x=10);

If you make changes to f then restart the kernel because "This will reset your notebook and remove all variables or methods you've defined"

Max
  • 85
  • 6
  • Yes, Max. It will work directly in Jupyter. However, I am used to putting all my functions in a file named "MyFunctions.py" and import this file whenever I want to use a function in this file. It won't work that way. – JackeyOL Jan 20 '20 at 03:48
  • 1
    If you have your f function defined in a separate file and have imported it with `from MyFunctions import f` try restarting the kernel. – Max Jan 20 '20 at 04:39