1

Just as the title said. I'm trying to figure out what does the '%%' mean. It seems to be not a Placeholder here?

%%file test_theano.py
from theano import config
print 'using device:', config.device
1

2 Answers 2

12

That %%file command is not Python, but rather an IPython "magic" command. It puts the content which follows into a file named by its parameter.

Some time ago it was renamed %%writefile, but the old name is still supported, though no longer documented. You can find the documentation for %%writefile here: https://ipython.org/ipython-doc/3/interactive/magics.html

If you try it in an IPython shell it will be quite clear what it does - it creates a file called test_theano.py in the current directory.

See also: How to load/edit/run/save text files (.py) into an IPython notebook cell?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @John Zwinck you are correct about it. I just realized it when I try it in an IPython notebook and get a file named test_theano.py.
1

Just to give an example to support what John wrote.

Run this in Ipython (or some Ipython shell such as Jupyter):

%%file test.py

some_list=[1,2,3]

The program will return

Writing test.py

IPython created a test.py file in the imediate environment. Open the test.py and you would see:

 some_list=[1,2,3]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.