i came across this completely randomly just curious because this this doesn't even look like a list .
This is a weird side-effect of the way the auto-quoting feature is implemented in IPython. In particular, every line entered at the IPython terminal is pattern-matched against this regex pattern:
import re
line_split = re.compile("""
^(\s*) # any leading space
([,;/%]|!!?|\?\??)? # escape character or characters
\s*(%{0,2}[\w\.\*]*) # function/method, possibly with leading %
# to correctly treat things like '?%magic'
(.*?$|$) # rest of line
""", re.VERBOSE)
In the case of the input ', = what iss this'
, this results in the following assignments:
pre, esc, ifun, the_rest = line_split.match(', = what iss this').groups()
print(repr(pre))
# ''
print(repr(esc))
# ','
print(repr(ifun))
# ''
print(repr(the_rest))
# '= what iss this'
Since esc
is a comma, the AutoHandler
prefilter reaches this if-else
statement:
if esc == ESC_QUOTE:
# Auto-quote splitting on whitespace
newcmd = '%s("%s")' % (ifun,'", "'.join(the_rest.split()) )
which modifies the command to become
In [19]: ifun=''
In [20]: the_rest='= what iss this'
In [21]: newcmd = '%s("%s")' % (ifun,'", "'.join(the_rest.split()) )
In [22]: newcmd
Out[22]: '("=", "what", "iss", "this")'
So in summary,
ifun
is an empty stringauto-quoting quotes the rest of the command string and forms
'%s("%s")' % (ifun,'", "'.join(the_rest.split()) )
as the new command. This "command" is then evaluated.
Hence, the result returned is the tuple ("=", "what", "iss", "this")
.
Just using ?
in IPython to see Introduction and overview of IPython's features.
Auto-Quoting
You can force auto-quoting of a function's arguments by using ',' as the first character of a line. For example::
In [1]: ,my_function /home/me # becomes my_function("/home/me")
If you use ';' instead, 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 ',' MUST be the first character on the line! This won't work::
In [4]: x = ,my_function /home/me # syntax error
EDIT: Sorry for the =
explanation. As @randomir said, the =
op discusses is here.
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