ipython/ipython — Issue #1060: Always save the .py file to disk next to the .ipynb
Author: fperez
Created: 2011-11-28 07:04:33+00:00
State: open
Labels: htmlnotebook, type-enhancement

The more I think about it, the more it seems to me that we should always write the .py file next to the notebook. This would let more library-like uses of the code in a much easier workflow than now (where one must go through the download button, that puts the files in a different place, etc). Furthermore, by putting at the top:

```
script = __name__ == `__main__`
```

one could then write the 'script parts' of the notebook with

```
if script:
... code
```

and the notebook could then be 'imported'. Since it would be a normal .py file, it would make it much easier to reuse code from one notebook to another via normal import mechanisms.

We may want later to consider other forms of cross-notebook referencing and loading, but I think that having out of the box mechanism to reuse notebooks as normal libraries would be extremely valuable.

@ellisonbg, @minrk, do you think it's easy to add a flag to do this automatically? I'd vote for having it always on, but I guess one could also want to turn it off, case in which it would need to be configurable. Ideally per-notebook, stored in the metadata, but initially it could be a server-level flag stored in the config file.