I stumbled upon some strange behaviour using ipython-notebook
and wondered what, if any, the purpose was. If you enter a semicolon before a function call, you get the result of applying the function to a string which reflects all the code after the function name. For example, if I do ;list('ab')
I get the result of list("('ab')")
:
In [138]: ;list('ab')
Out[138]:
['(', "'", 'a', 'b', "'", ')']
I'm using jupyter
with ipython 4
. It happens in ipython
as well as ipython notebook
.
Has anyone seen this before or does anyone know if it's intended and, if so, why?
Here's another example from the Dataquest — 28 Jupyter Notebook tips, tricks, and shortcuts post: # Use a semicolon to suppress the output of a final function.
This means that your kernel is busy. If you want to interrupt/stop the execution, go to the menu Kernel and click Interrupt. If it doesn't work, click Restart. You need to go in a new cell and press Shift + Enter to see if it worked.
The IPython Notebook is now known as the Jupyter Notebook. It is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. For more details on the Jupyter Notebook, please see the Jupyter website.
The IPython console is now deprecated and if you want to start it, you'll need to use the Jupyter Console, which is a terminal-based console frontend for Jupyter kernels.
It's a command for automatic quoting of function args: http://ipython.readthedocs.org/en/latest/interactive/reference.html#automatic-parentheses-and-quotes
From the docs:
You can force automatic quoting of a function’s arguments by using , or ; as the first character of a line. For example:
In [1]: ,my_function /home/me # becomes my_function("/home/me")
If you use ‘;’ the whole argument is quoted as a single string, while ‘,’ splits on whitespace:
In [2]: ,my_function a b c # becomes my_function("a","b","c")
In [3]: ;my_function a b c # becomes my_function("a b c")
Note that the ‘,’ or ‘;’ MUST be the first character on the line! This won’t work:
In [4]: x = ,my_function /home/me # syntax error
In your case it's quoting all characters including '
and (
and )
You get similar output here but without the single quotes:
In [279]:
;list(ab)
Out[279]:
['(', 'a', 'b', ')']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With