forked from catherinedevlin/minimal_ipython_extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloworld.py
31 lines (21 loc) · 890 Bytes
/
helloworld.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from IPython.core.magic import Magics, magics_class, line_magic, cell_magic
#-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
@magics_class
class HelloWorldMagics(Magics):
"""A simple Hello, <name> magic.
"""
@line_magic # or call with ("hi") to make %hi the magic name
@cell_magic
def helloworld(self, line='', cell=None):
"""Virtually empty magic for demonstration purposes.
Example::
In [1]: %load_ext helloworld
In [2]: %helloworld Catherine
Out[2]: u'Hello, Catherine'
"""
return "Hello, %s\n%s" % (line, cell or "")
def load_ipython_extension(ip):
"""Load the extension in IPython."""
ip.register_magics(HelloWorldMagics)