python 魔术命令,iPython - 在配置文件中设置魔术命令

I use iPython mostly via notebooks but also in the terminal. I just created my default profile by running ipython profile create.

I can't seem to figure out how to have the profile run several magic commands that I use every time. I tried to look this up online and in a book I'm reading but can't get it to work. For example, if I want %debug activated for every new notebook I tried adding these lines to my config file:

c.InteractiveShellApp.extensions = ['debug']

or

c.TerminalPythonApp.extensions = ['debug']

and I either get import errors or nothing. My (closely related) questions are the following:

What line to do I add to my ipython config file to activate magic commands? Some require parameters, e.g. %reload_ext autoreload and %autoreload 2. How do I also pass these parameters in the config file?

Can I separate which get added for terminal vs. notebooks in a single config file or must I set up separate profiles if I want different magic's activated? (e.g., matplotlib inline or not). Do the two lines above affect notebooks vs. terminal settings (i.e., c.InteractiveShellApp vs. c.TerminalPythonApp)?

Thank you!

解决方案

Execute magics as follows:

get_ipython().magic(u"%reload_ext autoreload")

get_ipython().magic(u"%autoreload 2")

You can put those lines in your startup script here:

~/.ipython/profile_default/startup/00-first.py

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值