Reputation: 8427
I am using an online jupyter notebook that is somehow configured to read all .py files as jupyter notebook files:
I am a big fan of this setup and would like to use it everywhere. On my own jupyter installation however, .py files are just interpreted as test files and are not by default loaded into jupyter cells. How can I achieve the same configuration for my jupyter notebook?
Upvotes: 7
Views: 729
Reputation: 681
You use the python code in your Jupyter Notebook by just pasting the whole code in a cell OR :
%load pythonfile.py
to load code from a file (not necessarily .py files) into a jupyter notebook cell;
%run pythonfile.py
in order to execute the file instead of loading it (outputs whatever that file outputs).
Also, pythonfile.py should exist in the cd
or you can use its full path.
Upvotes: 0
Reputation: 2406
What you're looking for is jupytext. You just need to install it into python env from which you're running your jupyter notebooks:
pip install jupytext --upgrade
Upvotes: 5
Reputation: 678
That's not exactly what you asked, but you can achieve something close to that by using the magic %load FILE.py
in a new jupyter notebook.
%load FILE.py
will copy the contents of FILE.py
in the current cell upon executing it.
Upvotes: 1