ipython-magic

IPython magic-command %notebook does not work when spaces are present in path (Google Colab)

前提是你 提交于 2021-01-29 08:51:05
问题 In jupyter-lab I can use the magic command %notebook $output_file_path to save the history notebook as a jupyter notebook. When I am working with Google Colab (mounting Google Drive) the path of my notebook folder is something like: root_path = 'gdrive/My Drive/Colab Notebooks/my_working_folder/' The problem is that, as I try to save the notebook history, the space between "My" and "Drive" makes the magic command fail output_file_path = 'gdrive/My Drive/Colab Notebooks/my_working_folder/nb

How do I define custom magics in jupyter?

ぃ、小莉子 提交于 2020-01-21 09:27:17
问题 I'm using Ubuntu 14.04 LTS with an Anaconda python installation: Python 3.5.1 :: Anaconda 2.4.1 (64-bit) I'm trying to use this recipe to enable C++ interactive compiling in my ipython notebooks: import IPython.core.magic as ipym @ipym.magics_class class CppMagics(ipym.Magics): @ipym.cell_magic def cpp(self, line, cell=None): """Compile, execute C++ code, and return the standard output.""" # Define the source and executable filenames. source_filename = 'temp.cpp' program_filename = 'temp.exe'

how to save the output of a cell in iPython notebook?

爷,独闯天下 提交于 2019-12-29 04:36:28
问题 I would like to be able to save the TEXT output of an iPython notebook cell into a file on disk. I have 2 additional requirements/requests: be able to re-run the cell and overwrite my output with whatever the latest is. also display the output within the notebook. I have figured out how to use the %%capture magic for some basic saving of an iPython notebook's cell into a file, but it does not seem flexible enough: it keeps appending every time I re-run the cell and I cannot get it to display

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

♀尐吖头ヾ 提交于 2019-12-28 04:58:04
问题 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 following: In[3]: %run %name% 回答1: IPython expands variables with $name , bash-style. This is true for all magics , not just %run . So you would do: In [1]: filename = "myscript.py" In [2]: %run $filename ['myscript.py'] myscript.py

How to save an ipython session if i used magic %paste ? (magic %save doesn't work)

自作多情 提交于 2019-12-25 03:37:06
问题 It's seems a fairly simple question but I didn't manage to correctly save my ipython session using magic "%save" If i use the magic "%paste" at any time during the session, saving the session results in this output : get_ipython().magic(u'paste') Of course, I would like the pasted code to be saved instead. Any ideas? 回答1: I can reproduce this with version 3.1.0 of ipython on Ubuntu $ ipython Python 2.7.6 (default, Mar 22 2014, 22:59:56) Type "copyright", "credits" or "license" for more

how does IPython magics work

怎甘沉沦 提交于 2019-12-23 12:34:17
问题 ipthon-sql is an extension of ipython, I first install it by pip install ipython-sql the project is here: https://github.com/catherinedevlin/ipython-sql and my problem is: when I enter %load_ext sql and press SHIFT+ENTER, what's the detailed procedure of IPython to execute this magic sentence? thanks ... 回答1: When you run any code in the notebook, an execute_request is sent via the notebook server, to a 'kernel', a process which executes your code. When the kernel receives your code, it runs

Configure the backend of Ipython to use retina display mode with code

旧城冷巷雨未停 提交于 2019-12-21 02:14:08
问题 I am using code to configure Jupyter notebooks because I have a repo with plenty of notebooks and want to keep style consistency across all without having to write lengthy setting at the start of each. This way, what I do is having a method to configure the CSS, one to set up Matplotlib and one to configure Ipython. The reasons I configure my notebooks this way rather than relying on a configuration file as per docs are two: I am sharing this repo of notebooks publicly and I want all my

Choose SQL as default cell magics for Jupyter Notebook

浪子不回头ぞ 提交于 2019-12-20 10:37:29
问题 I'm writing a Jupyter notebook for a database course; most cells will contain SQL code, for which I use the IPython SQL magic. Currently I have to prepend each cell with %%sql . Is there a way to avoid typing %%sql before each cell, by making it the default? I found a related question at How do I set up default cell magics for every ipython notebook cell?. However, I couldn't find a SQL kernel for Jupyter. 回答1: The Jupyter docs tell you how you can edit the CodeMirror settings. CodeMirror has

How to use pipe in IPython

╄→гoц情女王★ 提交于 2019-12-17 16:09:48
问题 In a Linux terminal, when the output of one command is too long to read in one page, I can do this: cat file | less so that I can read and scroll up and down the output from the cat file. How can I do this in IPython? For example, I tried this and it didn't work: whos | less My original problem is that the output from whos is too much to be seen by doing Shift+Page Up and I don't want to change the scroll buffer. 回答1: In IPython, you can use %page obj to show the object obj using your

How to access shell variable in ipython

自闭症网瘾萝莉.ら 提交于 2019-12-14 02:25:18
问题 Using the ! magic I can access env type environment variables, but not ones defined in my terminal, or .bashrc . $:/<path>/balter/chip-seq-analysis/chipseq$ echo $hg38 /<path>/genomes/hg38/release-85/Homo_sapiens.GRCh38.dna.primary_assembly.fa balter@exalab3:/<path>/balter/chip-seq-analysis/chipseq$ ipython Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:42:40) Type "copyright", "credits" or "license" for more information. IPython 5.1.0 -- An enhanced Interactive Python. ?