Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython %save magic error

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!

like image 209
agconti Avatar asked Jun 11 '13 00:06

agconti


People also ask

What are magic commands in IPython?

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.

What is %% capture in Python?

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.

What is line magic function?

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.


1 Answers

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.

like image 160
punchagan Avatar answered Sep 18 '22 22:09

punchagan