I tried the following very known example of %alias in Jupiter Notebook:

%alias bracket echo "Input in brackets: <%l>"
bracket hello world 

This is supposed to output:

Input in brackets: <hello world>

Instead, I get the following:

File "<ipython-input-12-237eb6e9d860>", line 1
alias bracket echo "Input in brackets: <%l>"
            ^
SyntaxError: invalid syntax

I have cleared everything, shutdown the book and even restarted the kernel. So it's not a question of some "garbage" in cache. I have tried a lot of different things with %alias. Nothing works. I even get "'xxx' is not defined", where 'xxx' is the name used for alias.

Additional info:

1) If I execute just bracket (no argument), I receive an error: "bracket is not defined". I find this quite crazy. I hope you don't and know the reason why this happens.

2) I am using Jupyter Notebook 5.6.0.

2 Answers

0
Community On

Python 3.6.8

jupyter version: 4.4.0

Notebook server: 5.7.8

%alias bracket echo "Input in brackets: <%l>"
bracket hello world
bracket'hello world'
bracket(1)

Output:

"Input in brackets: <hello world>"
"Input in brackets: <'hello world'>" 
"Input in brackets: <(1)>" 
0
clayton On

I was able to duplicate your issue and putting a % in front of the bracket calls treats them as the actual alias you are creating.

%alias bracket echo "Input in brackets: <%l>"

%bracket hello world
%bracket 'hello world'
%bracket (1)

Output:

"Input in brackets: <hello world>" 
"Input in brackets: <'hello world'>" 
"Input in brackets: <(1)>" 

For notebook server 5.7.4, Python 3.7.1, and IPython 7.2.0