eliu
eliu

Reputation: 2479

Jupyter notebook's ability to retain variables on script exit, Any other IDE can do it?

Context:

Jupyter notebook has this nice ability to store variable values even when a block of code executed and exited. It is a more powerful version of "break point" in other IDEs. So far, I have noticed some benefits from this jupyter notebook ability:

  1. You can run the lengthy part of your code only once and use its results over and over again without rerunning them.
  2. you can inspect your current variables more flexibility, print them on console or into a file or into a table.
  3. you can try tweaking variables as well, before feed it to the next code block. There can be draw back to this, after tweaking my variables, they are forever changed, so I have to include lines of boilerplate code in my subsequent notebook script after the lengthy script: lengthy_variable_new = lengthy_variable_original.copy()
    # do things with lengthy_variable_new

Now, let's imagine a a new ability: "saveState" a script, in which you can save all variables created by the user and all hidden ones, everything that is currently on heap or stack. So you can continue coding after the saveState point but you can restore the saveState point anytime you want.

I understand that python language itself can only pickle things you want. It is handy for some cases but not all.

Question:

Is there a proper term describing my "saveState" concept?
Do we have it in pycharm or any other IDEs?
I personally believe there is either a better way, or what I want is very hard to implement so that is almost easier just to re-run the code compared to restoring everything back to memory.

Upvotes: 2

Views: 1852

Answers (1)

Alan Höng
Alan Höng

Reputation: 113

I think your state may refer to a stack frame (more or less).

PyCharm and probably other IDEs have a similar tool. If you are debugging your code and reach a breakpoint you have the possibility to open an interactive ipython console in which you can inspect all current variables in the stack frame, though you cant alter them.

I personally prefer debugging in PyCharm and use Jupyter Notebooks more for interactive exploring data or some new piece of code. It is kind of hart to debug loops in Notebooks and some other things like iterators too.

Upvotes: 1

Related Questions