ipython-magic

iPython custom cell magic – store output in variable?

iPython custom cell magic – store output in variable? Question: I recently discovered iPython magic functions and wrote some custom magic. I would like to use cell magic to parse strings, change them slightly and return the result. Is there a way to store the output of my custom cell magic function in a variable? …

Total answers: 1

Ignore IPython magic in python

Ignore IPython magic in python Question: 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 keep reload-ing the modules after I make …

Total answers: 5

How to write an ipython alias which executes in python instead of shell?

How to write an ipython alias which executes in python instead of shell? Question: We can define an alias in ipython with the %alias magic function, like this: >>> d NameError: name ‘d’ is not defined >>> %alias d date >>> d Fri May 15 00:12:20 AEST 2015 This escapes to the shell command date …

Total answers: 2

Pipe Ipython magic output to a variable?

Pipe Ipython magic output to a variable? Question: I want to run a bash script in my ipython Notebook and save the output as a string in a python variable for further manipulation. Basically I want to pipe the output of the bash magic to a variable, For example the output of something like this: …

Total answers: 3

How to (intermittently) skip certain cells when running IPython notebook?

How to (intermittently) skip certain cells when running IPython notebook? Question: I usually have to rerun (most parts of) a notebook when reopen it, in order to get access to previously defined variables and go on working. However, sometimes I’d like to skip some of the cells, which have no influence to subsequent cells (e.g., …

Total answers: 8

How to pass a variable to magic ´run´ function in IPython

How to pass a variable to magic ´run´ function in IPython Question: I want to do something like the following: In[1]: name = ‘long_name_to_type_every_now_and_then.py’ In[2]: %run name but this actually tries to run ‘name.py’, which is not what I want to do. Is there a general way to turn variables into strings? Something like the …

Total answers: 5