I use a Jupyter Notebook to write a small program. Therefore, I want to write some cells into a .py file.
I use this magic %%writefile -a myfile.py
. It works, but the problem is that the content is appended without a new line. So, I have to manually add a line break to myfile.py
after running the cells.
How can I avoid this problem?
Just put an empty line after %%writefile
in the cell. For example:
In [1]:
%%writefile -a myfile.py
a = 1
In [2]:
%%writefile -a myfile.py
b = 2
Now:
In [2]:
%less myfile.py
a = 1
b = 2
Add two empty lines to the beginning of a cell for an empty line between
the exported code of two cells in the file myfile.py
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With