Does Jupyter Notebook have a file rename hook? - jupyter-notebook

I've written a custom pre_save_hook that's similar to the one that the Jupyter Notebook docs provide. The one I've written adds metadata to a notebook when the notebook is saved. However, the pre_save_hook doesn't seem to get called when a notebook is renamed. Is there something similar to the pre_save_hook for renaming a notebook?

Related

Where does Jupyter Notebook save files?

So I'm just beginning my programming/coding journey. I've downloaded Anaconda and made a shortcut for Jupyter Notebook on my desktop. I tried using my first file the other day, and I'm not sure where it's being saved to. Also, I basically don't want Jupyter to save any Notebook I do once I close the Notebook, unless I specifically save it myself - I just use it for 'working out' if you like.
Here is the image showing what I mean
Like, where is that untitled.ipynb file being saved? And, how can I adjust my settings in Jupyter Notebook such that these files aren't saved and are discarded automatically so I can use them as I describe just for 'working out'?
By default the ipynb files are stored to your user profile:
C:\Users\yourlogin
How to disable autosave has already been described here:
Turn Off Autosave in IPython Notebook
I don't recommend doing that.

How to rename a Jupyter Notebook programmatically?

Is there a command or any other way to rename a Jupyter Notebook in execution time?
Like appending a string created while running the notebook to the notebook's name.
As answered in this other question, one can simply call the javascript magic command and Jupyter.notebook.rename().
%%js
Jupyter.notebook.rename(newNameString)

How do I set the save location of a session in Jupyter notebook?

I'm working with Jupyter Notebook version 4.1.0 and can't seem to manually select the save path.
How does one manually specify where a session is saved?
You can launch jupyter notebook from the command line from inside the desired folder path. This will set the current folder as the start of the directory tree in Jupyter.
If we already have a session running, we can select the option IPython Notebook (.ipynb), from the file menu, under the Download as option. After saving the Notebook to a desired path, we can open it using the method described above.

Use workspace of an RStudio session in Jupyter notebook

As my RAM is scarce, I'd like to not replicate data and use objects created in an RStudio session inside my Jupyter notebook (running w/ R kernel).
Any idea how to do it?
Basically I'd like to use the same workspace in both, the RStudio and the Jupyter notebook session.
Thanks for help!
One problem I encountered with an R notebook in Jupyter, though, was saving my workspace. In a normal R session I’m used to saving my workspace at the end of the session and coming back to it later to pick up where I left off. However, with the Jupyter notebook I found that I had to rerun all the code to regenerate all the objects again! This appears to be an issue for Python notebook users too.
There’s a very simple fix for this: Just run the standard R command
save.image()
Your workspace will then be saved to the usual hidden .RData file in the same folder as the Jupyter notebook. If you want to share the code and the workspace, you’ll have to make sure that you copy both the notebook file and the .RData file that goes along with it.
Likewise, if you start a notebook in a folder that already has an .RData file, you’ll find that you can access that workspace from the Jupyter notebook – just run ls() to see what’s there.

How to develop with ipython notebook

I am new to IPython Notebook. I am using the Anaconda distribution on CrunchBang (Waldorf). My development cycle is as follows:
1. Open Spyder.
2. Open the .py file if not already loaded
3. Start IPython Notebook
4. Open the specific notebook from the main IPython screen
5. Select Cell/Run All
6. Note errors. If none goto step 11.
7. Save and close the notebook
8. Shutdown the notebook from main IPython screen
9. Correct errors in Spyder and save
10. go to step 4
11. Move on to the next part of the project and start the process over.
Is there a better approach for a noob? This really gets monotonous although I am learning quite a bit.
Thanks in advance
Forget Spyder for the time being just use the IPython notebook.
1, write code in notebook
2. test it
3. when done if needed make a py file...
You really will only need Spyder later for starting out it just complicates things for no gain
Use Spyder and .py files for writing big functions, classes, modules, tests, etc.
Use IPython notebooks for interactive work where you want to keep the output together with the code (e.g. data processing and analysis, demos, etc.).
To add to Ian's answer, another useful tool is the autoreload extension, which reloads modules automatically when they are changed.
To use, type into your IPython console or notebook:
%load_ext autoreload
%autoreload 2
For example:
This way you can work on a Python file and an IPython notebook at the same time, without having to reload the Python file after each change.
In addition to #dartdog's answer about developing directly in the notebook, if you must edit .py files used by the notebook then note the reload function which allows you to re-import already imported modules without having to shutdown and reopen the notebook.

Resources