如果我在 iPython 中键入 /,为什么会得到空元组?
Why do I get the empty tuple if I type / in iPython?
打开 iPython 并输入:
/
按回车键并想知道结果:
()
你不能分配它,我猜它与 shell 功能有关。
编辑:
您可以分配给它:
p = Out[xx]
但不是直接的:
p = /
将给予:
SyntaxError
确实是一个空元组。
这是可调用 objects/names 的一项便利功能。它不是空元组,而是括号补全。来自 iPython 的帮助系统 (?
):
Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
Auto-parentheses
Callable objects (i.e. functions, methods, etc) can be invoked like
this (notice the commas between the arguments)::
In [1]: callable_ob arg1, arg2, arg3
and the input will be translated to this::
callable_ob(arg1, arg2, arg3)
This feature is off by default (in rare cases it can produce
undesirable side-effects), but you can activate it at the command-line
by starting IPython with --autocall 1
, set it permanently in your
configuration file, or turn on at runtime with %autocall 1
.
You can force auto-parentheses by using '/' as the first character
of a line. For example::
In [1]: /globals # becomes 'globals()'
打开 iPython 并输入:
/
按回车键并想知道结果:
()
你不能分配它,我猜它与 shell 功能有关。
编辑:
您可以分配给它:
p = Out[xx]
但不是直接的:
p = /
将给予:
SyntaxError
确实是一个空元组。
这是可调用 objects/names 的一项便利功能。它不是空元组,而是括号补全。来自 iPython 的帮助系统 (?
):
Auto-parentheses and auto-quotes (adapted from Nathan Gray's LazyPython)
Auto-parentheses
Callable objects (i.e. functions, methods, etc) can be invoked like this (notice the commas between the arguments)::
In [1]: callable_ob arg1, arg2, arg3
and the input will be translated to this::
callable_ob(arg1, arg2, arg3)
This feature is off by default (in rare cases it can produce undesirable side-effects), but you can activate it at the command-line by starting IPython with
--autocall 1
, set it permanently in your configuration file, or turn on at runtime with%autocall 1
.You can force auto-parentheses by using '/' as the first character of a line. For example::
In [1]: /globals # becomes 'globals()'