I'm trying to save a python file that I loaded into my IPython notebook with the %loadpy
magic. When I try and save the file with %save settings.py
I get the following error:
File `settings.py` exists. Use `%save -f 'settings.py' -f` to force overwrite
Then when I use %save -f 'settings.py' -f
I get the error:
'-f' was not found in history, as a file, url, nor in the user namespace.
%save -f 'settings.py'
yeilds the error '' was not found in history, as a file, url, nor in the user namespace.
as well.
Any idea how to correctly save a .py
file so that it overwrites the previous version? Thanks!
The magic commands, or magics, are handy commands built into the IPython kernel that make it easy to perform particular tasks, for example, interacting Python's capabilities with the operating system, another programming language, or a kernel. IPython provides two categories of magics: line magics and cell magics.
Capturing Output With %%capture IPython has a cell magic, %%capture , which captures the stdout/stderr of a cell. With this magic you can discard these streams or store them in a variable.
Magic commands come in two flavors: line magics, which are denoted by a single % prefix and operate on a single line of input, and cell magics, which are denoted by a double %% prefix and operate on multiple lines of input.
In [13]: %save -f settings.py 1-10 # saves lines 1 to 10 to settings.py
In [14]: %save? # Gives you the help on the save command
Usage:
%save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
n1-n2, n3-n4 are ranges of lines that you want to save. n5, n6 are individual line numbers that you want to save. Add -f
option to force save.
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