Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a magic function in IPython?

Tags:

python

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)
like image 624
ceiling cat Avatar asked Feb 23 '26 17:02

ceiling cat


2 Answers

From IPython 0.13, there's a new %alias_magic magic function, which you would use as:

%alias_magic pp paste
like image 86
Thomas K Avatar answered Feb 26 '26 08:02

Thomas K


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'
   ... 
like image 24
root Avatar answered Feb 26 '26 07:02

root



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!