7

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

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Ron
  • 271
  • 4
  • 15

3 Answers3

7

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

dartdog
  • 10,432
  • 21
  • 72
  • 121
  • Dartdog, Thanks for the advice. I was using Spyder to keep the clutter out of the notebook. But I think you're right. It just becomes too confusing jumping back and forth. With Ian's input above I'll retry the notebook only approach. – Ron Feb 13 '14 at 01:37
  • Dartdog, I was just thinking that part of the reason I was using separate files is the issue of location of functions in the notebook. Do you place all your functions at the beginning of the notebook or does it matter? – Ron Feb 13 '14 at 02:30
  • You can dev with your functions as you please and arrange them later. Just do what feels right. Eventually you move all imports to the front followed by functions. But sometimes as you are going along you may do a function and call it in a cell for testing nothing stops you from re arranging later – dartdog Feb 13 '14 at 02:41
  • Thank you for the advice and direction. I really appreciate guidance from knowledgeable people. – Ron Feb 13 '14 at 20:47
7

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:

enter image description here

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.

Community
  • 1
  • 1
ostrokach
  • 17,993
  • 11
  • 78
  • 90
  • Does this actually work for you in IPython notebooks too? I only found this to work on the console before. – Mark Horvath Jan 19 '16 at 12:19
  • 1
    @MarkHorvath It works for me (added a screenshot). But I think you have to load `autoreload` before the other modules for it to work. – ostrokach Jan 19 '16 at 21:05
  • Great stuff! I had bad experience in earlier versions in IPython notebook (not sure if I made a mistake or it really didn't work). Confirmed, I does work now! – Mark Horvath Jan 20 '16 at 16:28
2

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.

Community
  • 1
  • 1
Ian
  • 1,483
  • 13
  • 14
  • Thanks for the advice. For some reason (noob?) I thought that only worked for IPython and not the notebook. Very lazy of me. – Ron Feb 13 '14 at 01:34