0

I have two python files, one is func.py where in this file I define the function

import matplotlib.pyplot as plt

def lineplot(x,y,clip):
    fig, ax = plt.subplots()
    ax.plot(x,y,'k-', linewidth=0.2)
    ax.plot(lo,la,marker='.', color='r')

Then, in my second file main.ipynb, I call this function

import func as f

f.lineplot(x,y,clip)

I run main.ipynb and it has an error name lo is not given.

I find lo and la in function lineplot are not in the argument list. So I change func.py as

import matplotlib.pyplot as plt

def lineplot(x,y,clip,lo,la):
    fig, ax = plt.subplots()
    ax.plot(x,y,'k-', linewidth=0.2)
    ax.plot(lo,la,marker='.', color='r')

After that, I revise main.ipynb,

import func as f

f.lineplot(x,y,clip,lo,la)

but this time it gives me an error: lineplot() takes 3 positional arguments but 5 were given

Does anybody know why it happens and how to fix it? I use Jupyter notebook.

janet
  • 31
  • 1
  • Did you `reload()` the function in `main` after you changed it in `func`? – G. Anderson Sep 03 '21 at 23:04
  • Does `import func as f` equivalent to load the revised function to the main environment? – janet Sep 03 '21 at 23:26
  • Not if you haven't closed/restarted the jupyter kernel, if the module exists in the namespace it may not reload when you call import again. See [this question for ideal methods](https://stackoverflow.com/questions/1739924/python-reload-component-y-imported-with-from-x-import-y) – G. Anderson Sep 03 '21 at 23:29

0 Answers0