Questions tagged [ipython-magic]

A set of pre-defined "magic functions" of IPython that used with the command-line syntax.

A set of pre-defined "magic functions" of that used with the command-line syntax. There are two types of magic functions line-oriented and cell-oriented. The lines start with a magic % and executed from the command line. They get into an argument the rest of the line, where the arguments are passed without parentheses and quotation marks. Cell magic begins with the double %%, and they are functions that get in an argument not only the rest of the line, but the line below it in a separate argument.

169 questions
1
vote
2 answers

what does '%%file test.py' mean in python?

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
yunlai xu
  • 13
  • 1
  • 4
1
vote
1 answer

Create a Cell magics that Execute code before and after the cell execution

I have a special Class that capture and process the logs of a given algorithm. This looks like this report = Report2File(logger,"./path") report.start() solveProblem() report.stop() del report I would like to be event more lazy and write…
xNok
  • 98
  • 1
  • 7
1
vote
1 answer

IPython: How can I run a script, enter an interactive session, and run "whos()" using only startup options/flags?

I'd like to be able to both start an interactive session after completing a script (which I know can be done with ipython -i myscript.py), and have the shell execute the whos() command immediately afterward. This will help my workflow by allowing my…
Luke Davis
  • 2,548
  • 2
  • 21
  • 43
1
vote
1 answer

ipython-cypher %cypher magic broken in neo4j 3.0?

I am using jupyter notebook and ipython-cypher but since neo4J version 3.0 has a mandatory password change I seem not to be able to use the %cypher magic... (single % ... %%cypher works as I can pass the connection url on the first line) results =…
Hugo Koopmans
  • 1,349
  • 1
  • 15
  • 27
1
vote
1 answer

How to access shell variable in ipython

Using the ! magic I can access env type environment variables, but not ones defined in my terminal, or .bashrc. $://balter/chip-seq-analysis/chipseq$ echo…
abalter
  • 9,663
  • 17
  • 90
  • 145
1
vote
1 answer

ipython 5.1 export interactive session to script

So, I know I can export an ipython session to a notebook, and then convert that notebook to many format using jupyter nbconvert .... However, the doc also says I should be able to export the session directly to a python script if I give the…
Charles Langlois
  • 4,198
  • 4
  • 16
  • 25
1
vote
1 answer

ipython3 - Almost every time I tab complete in ipython3 it runs %rehashx, is there a workaround?

I've tried googling around but haven't found much / anything, the following also doesn't help at all... https://ipython.org/ipython-doc/3/interactive/magics.html typical usecase is: In [31]: from sqlalch Caching the list of root modules,…
evan54
  • 3,585
  • 5
  • 34
  • 61
1
vote
1 answer

IPython (Jupyter) cell magics and cross-language interaction

In a normal ipython notebook or repl session, I can refer to previously-run cells using the _# notation. However, this is not possible when using cell magics such as %%perl or %%bash because these cells do not have entries in _oh. Nor can I find a…
Rache
  • 236
  • 2
  • 11
1
vote
1 answer

How to add a custom flag to IPython's magic commands? (.ipy files)

Is it possible to add a custom flag to IPython's magic command? To be more specific, I want to use the %run command with a homemade flag: %run script.ipy --flag "option" and be able to use "option" inside the script. For .py files, the answer is…
Laurent
  • 73
  • 7
1
vote
0 answers

Bundle functions into modules within single IPython notebook

If you're writing a conventional Python program, the most natural way of putting multiple function together into a single function-bundle to access them as bundle_name.function_name() is to locate them is a separate file and import it as a module…
Ben Usman
  • 7,969
  • 6
  • 46
  • 66
1
vote
0 answers

How to get colored output from magic commands such as `!grep` when using IPython as the shell?

In the bash shell, using for example grep would result in every line containing the pattern to be returned and the pattern to be highlighted in red bold font in each of these lines. However, when I use !grep from the IPython shell,…
joelostblom
  • 43,590
  • 17
  • 150
  • 159
1
vote
0 answers

%paste magic when connecting to a ipython notebook kernel

I am using the ipython notebook to code but sometimes I like to connect to the kernel on a terminal to do some debugging. To launch the interactive terminal connected to my kernel I do: ipython console --existing…
sirip82
  • 187
  • 1
  • 1
  • 8
1
vote
1 answer

Pylab / matplotlib magic in IPython: supress loading message

Currently in IPython, when you call %pylab inline or %matplotlib inline the following message displays under the code block. "Populating the interactive namespace from numpy and matplotlib" How I can suppress this message from being displayed?
pyCthon
  • 11,746
  • 20
  • 73
  • 135
1
vote
0 answers

IPython's magic %paste silently fails with ← symbol

IPython's magic %paste silently ignored everything in my clipboard under certain circumstances. The causal agent: a commented ← symbol. This is automatically generated in Google docs by typing <-- and space. Comparison of outcomes, when copy-pasting…
hello_there_andy
  • 2,039
  • 2
  • 21
  • 51
1
vote
1 answer

Memory address of ipython magic functions

I have been experimenting with the scriptable visualization tool mayavi from ipython's terminal. Mayavi uses the wx backend, and therefore I call the magic function just to check the address, then change the gui and check again the address to make…
SAAD
  • 759
  • 1
  • 9
  • 23