Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a function from another cell in iPython

In a cell I have

  def function():
        stuff

In a cell below the previously mentioned cell, I call

   function()

The error I get is:

   name 'function' is not defined.

How do I call a function in another cell in iPython?

like image 230
lars Avatar asked Aug 29 '14 03:08

lars


1 Answers

Run the cell in which you defined the function first, then run the cell you call it from. If you make any changes to the function later, run that cell again for the changes to take effect, otherwise your calls will run the un-changed function.

or, as @ymonad pointed out, run all cells each time. it takes care of the trouble as long as function definition comes before any point it is called upon.

like image 87
Alvin Wanda Avatar answered Oct 14 '22 08:10

Alvin Wanda