简体   繁体   中英

How to rename a magic function in IPython?

I'd like to rename %paste to something like %pp so that it takes fewer keystrokes. I worked out a way to do that but it seems complicated. Is there a better way?

def foo(self, bar):
    get_ipython().magic("paste")

get_ipython().define_magic('pp', foo)

从IPython 0.13开始,有一个新的%alias_magic魔术函数,您可以将其用作:

%alias_magic pp paste

use %alias magic to do it (if you want it to be permanent use %store ):

In [8]: %alias??

"""Define an alias for a system command.

   '%alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
   ... 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM