Show More
@@ -37,6 +37,40 b' arguments::' | |||
|
37 | 37 | -o OPTION, --option OPTION |
|
38 | 38 | An optional argument. |
|
39 | 39 | |
|
40 | ||
|
41 | Here is an elaborated example that uses default parameters in `argument` and calls the `args` in the cell magic:: | |
|
42 | ||
|
43 | from IPython.core.magic import register_cell_magic | |
|
44 | from IPython.core.magic_arguments import (argument, magic_arguments, | |
|
45 | parse_argstring) | |
|
46 | ||
|
47 | ||
|
48 | @magic_arguments() | |
|
49 | @argument( | |
|
50 | "--option", | |
|
51 | "-o", | |
|
52 | help=("Add an option here"), | |
|
53 | ) | |
|
54 | @argument( | |
|
55 | "--style", | |
|
56 | "-s", | |
|
57 | default="foo", | |
|
58 | help=("Add some style arguments"), | |
|
59 | ) | |
|
60 | @register_cell_magic | |
|
61 | def my_cell_magic(line, cell): | |
|
62 | args = parse_argstring(my_cell_magic, line) | |
|
63 | print(f"{args.option=}") | |
|
64 | print(f"{args.style=}") | |
|
65 | print(f"{cell=}") | |
|
66 | ||
|
67 | In a jupyter notebook, this cell magic can be executed like this:: | |
|
68 | ||
|
69 | %%my_cell_magic -o Hello | |
|
70 | print("bar") | |
|
71 | i = 42 | |
|
72 | ||
|
73 | ||
|
40 | 74 | Inheritance diagram: |
|
41 | 75 | |
|
42 | 76 | .. inheritance-diagram:: IPython.core.magic_arguments |
General Comments 0
You need to be logged in to leave comments.
Login now