1

Essentially I have 2 functions, the second takes in the output of the first as a parameter. Something like:

value1 = function1()
value2 = function2(value1)

I want to avoid running the first since it takes a long time to run (5mins+). In jupyter notebook you can just comment out the first line and it will run no problem, but in Spyder it says value1 is not defined. Is there any way to do this in spyder?

fthomson
  • 773
  • 3
  • 9
  • Just run the function once, print `value1`, then comment out the first line and simple add something like `value1 = 42` or whatever the result of function1 is. – NotAName Nov 05 '20 at 23:53
  • alternatively, for more complex data, you can store your result in a text file and make the function2 dig the data from the file – Mayeul sgc Nov 05 '20 at 23:56
  • I should have added that value1 is actually a pretty large dataframe. But I was hoping that there would just be a quick way like in Jupyter. I will write it to a pkl/txt instead. Thanks – fthomson Nov 06 '20 at 00:03

1 Answers1

2

(Spyder maintainer here) This is the perfect case for code cells, which are blocks of code that you can evaluate independently.

For that you need to create a cell between value1 and value2 by adding a comment like this between them:

value1 = function1()

# %%

value2 = function2(value1)

Then you can run the cell that contains value1 only once by putting the cursor there and pressing Shift+Enter. Afterwards, you can modify the contents of the second cell and run it as many times as you want with Shift+Enter, without evaluating value1 again.

Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124