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
4
votes
3 answers

IPython %store magic not persisting

I'm trying to get an IPython alias to persist, and according to docs the %store magic offers this feature. But it's not working: $ echo 'print("hello world!")' > test.py $ ipython In [1]: alias potato python /tmp/test.py In [2]: potato hello…
wim
  • 338,267
  • 99
  • 616
  • 750
4
votes
1 answer

Looping over magic function in IPython notebook

I want to accomplish a loop over R code within an IPython notebook. What is the best way to do this? l = [] for i in range(10): # execute R script %%R -i i -o result #some arbitrary R code # and use the output …
Bjoern
  • 171
  • 1
  • 11
3
votes
2 answers

Jupyter %%prun magic output not displayed properly in VS Code

Since very recently I have a problem where the output of %%prun is not displayed properly in VS Code Jupyter (all output is on one line instead of in a nicely formatted table). I tried reloading the window and restarting Jupyter but the problem…
Louis M
  • 4,036
  • 4
  • 21
  • 25
3
votes
1 answer

Add reStructuredText support for Juptyer notebooks

I needed to view reStructuredText files in JupyterLab, and the best I found so far was @akaihola's answer to a related issue on github. I added a work around that would allow rendering the file without viewing the source, provided below.
eldad-a
  • 3,051
  • 3
  • 22
  • 25
3
votes
1 answer

%lprun could not get result in jupyternotebook

Code: def combCreate(grp,num): d = chain(*(map(lambda x: (combinations(x,num)),grp))) return set(d) # Comb DataFrame abt Freq & occured date def combFrame(grp): arr = df.loc[:,'date':'6th'].values t = [] cnt = [] for i in…
Jack
  • 1,724
  • 4
  • 18
  • 33
3
votes
1 answer

atexit alternative for ipython

python has atexit module to register functions to run prior to closing of the interpreter. This question nicely why atexit is not called. I'm wondering if there is an alternative for ipython to register a function prior to exiting something which…
magu_
  • 4,766
  • 3
  • 45
  • 79
3
votes
1 answer

How do I assign the result of iPython profiler %%prun -r to a variable?

In the docs of the iPython magic functions it says: Usage, in cell mode: %%prun [options] [statement] code... code... In cell mode, the additional code lines are appended to the (possibly empty) statement in the first line. Cell mode allows…
patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
3
votes
1 answer

IPython custom tab-completion for user magic function

In IPython, it is fairly easy to provide tab-completion for user-defined object: simply define a __dir__ method that returns a list of strings to the object. IPython also provide us with a way to define our own custom magic functions using the handy…
Romain G
  • 1,276
  • 1
  • 15
  • 27
3
votes
1 answer

IPython Notebook Magic Functions with environment variables

Can I use an environment variable with a magicfunction such as writefile in my ipthon notebook? %env WORKING_DIR=/my/path/to/my/file !echo $WORKING_DIR /my/path/to/my/file but %%writefile $WORKING_DIR/myfile.txt sometext IOError: [Errno 2] No…
jwillis0720
  • 4,329
  • 8
  • 41
  • 74
3
votes
5 answers

Ignore IPython magic in python

What is the best way to ignore IPython magic when running scripts using the python interpreter? I often include IPython magic in my script files because it work with the code interactively. For example, with the autoreload magic, I don't have to…
ostrokach
  • 17,993
  • 11
  • 78
  • 90
3
votes
0 answers

Glmer Results Differences Through Pure R and rmagic

I am trying to duplicate the results from pure R code that uses lme4 glmer with Pandas -> R -> glmer. The original output is %load_ext rpy2.ipython %R library(lme4) %R data("respiratory", package = "HSAUR2") %R write.csv(respiratory,…
BBSysDyn
  • 4,389
  • 8
  • 48
  • 63
3
votes
1 answer

IPython: Alias which uses a magic function itself

I couldn't find anything about this so Im asking here: I want to create an alias in IPython which itself uses an IPython-magic-function. That means: I often need to to retype %run process.py thus I'd like to create an alias like this: %alias rp…
tim
  • 9,896
  • 20
  • 81
  • 137
3
votes
3 answers

Installing pymatbridge on Windows

In version 0.3 of pymatbridge, an additional dependency was added for ZMQ. To install this version, you might therefore need to compile a messenger mex extension linking against a dll of zeromq. However, this turns out to be rather difficult to do…
arokem
  • 579
  • 4
  • 15
3
votes
1 answer

IPython Cell Magic to Run this Cell in Client and in All Engines

In IPython for parallel execution we have multiple engines. The jobs are dispatched to them using: %%px cell magics to set up the environment in the clients and then using DirectView map_sync to run the various experiments. The experiments return a…
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137
3
votes
2 answers

`get_ipython' doesn't work in a startup script for IPython / IPython Notebook...?

So - the good folks in the ROOT community made the following magic: # This is for intercepting the output of ROOT # In a cell, put %%rootprint so that the output that would normally be # sent directly to the stdout will instead be displayed in the…
Bill Mills
  • 411
  • 6
  • 16