On Oct 29 2020, at 1:53 pm, Gavin Scott <ga...@learn.bio> wrote: > If I execute a cell containing only a semicolon in 2.2.6 JupyterLab and 3.8.5 > Anaconda Python, I get back an empty string which seems odd. If I try two > semicolons I get an error that suggests each one is getting replaced by ("") > > [snip] > > The python REPL rejects these as SyntaxErrors. Bug? Or some obscure Jupyter > thing? This behavior is being caused by the IPython kernel. (I can see the same behavior in the IPython repl.) IPython contains several features for automatically calling functions and quoting arguments [1]. Specifically, if a line begins with a semicolon, the first word is treated as a callable, and the rest of the line is quoted as a single argument. That is, the entry > ;func some args gets transformed to > func('some args')
In a little testing, it appears that if no string follows the callable name, the empty string is used as a default. Thus > ;func becomes > func('') Moreover, if there is whitespace following the semicolon, an identity function is assumed. Thus, > ; a b becomes > (lambda x: x)('a b') which returns > 'a b' My guess, then, is that > ; becomes > (lambda x: x)('') returning > '' However, the entry > ;; doesn't have whitespace following the first semicolon, so the identity function behavior is not invoked. The second semicolon marks the end of the statement, so IPython tries to divide the text between there ('') into a callable name and an argument. It uses the empty string for the function name, and then fills in the empty string default argument, and tries to execute > ('')('') giving the error you note. Arguably, this is a bug, but it's hard to say what the "correct" behavior should be. Hope that helps, Robert [1] https://ipython.readthedocs.io/en/stable/interactive/reference.html?highlight=automatic#automatic-parentheses-and-quotes -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/47B670EA-5632-4887-B9EE-67C9FA89D091%40getmailspring.com.