ipython - 为什么问号在 iPython 中并不总是有效?

标签 ipython

有时当我输入问号时,如下所示:

data["mass"]?

我收到语法错误。我必须使用 help(data["mass"]) 才能获取信息。有什么想法可以让这项工作发挥作用吗?

最佳答案

我发现 ? (和 ??)在应用于变量或函数名称而不是表达式时效果最佳。

 x = data['mass']
 x?

 y = 1.232
 y?

 z = 'astring'
 z?

可能有一些表达式有效,但通常无效。我最常使用它来获取有关函数的信息,而不是获取任意对象的信息。在上面的表达式中,y? 为我提供了有关 float(type(y) 创建者)的信息。

<小时/>

我怀疑?使用了完成符

http://ipython.readthedocs.org/en/stable/api/generated/IPython.core.completer.html

The evaluation of the NAME.NAME... form may cause arbitrary application defined code to be executed if an object with a getattr hook is found. Since it is the responsibility of the application (or the user) to enable this feature, I consider this an acceptable risk. More complicated expressions (e.g. function calls or indexing operations) are not evaluated.

scipy.sparse 矩阵是定义自己的 __getattr__ 的类的示例。

来自%magic

%pinfo:
    Provide detailed information about an object.

    '%pinfo object' is just a synonym for object? or ?object.
%pinfo2:
    Provide extra detailed information about an object.

    '%pinfo2 object' is just a synonym for object?? or ??object.

%pinfo? 返回语法错误的情况下似乎返回未找到

In [265]: %pinfo data['mass']
Object `data['mass']` not found.
In [266]: %pinfo x+1
Object `x+1` not found.
In [267]: %pinfo data.get
Type:        builtin_function_or_method
String form: <built-in method get of dict object at 0xb2d700ac>
Docstring:   D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.

关于ipython - 为什么问号在 iPython 中并不总是有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36226945/

相关文章:

ipython - IPython 魔法是如何工作的

python - 将 pywin32 与 iPython 结合使用

python - 如何使用脚本重新创建 IPython 的 '--pylab' 选项的效果?

由于不存在的大文件导致 git push 错误

python - 系统退出 : 2 error when calling parse_args() within ipython

python - 在 python 3.6.1 中找不到平台相关库 <exec_prefix>

python - Ipython 交互功能绘制多个图而不是编辑一个图

python - 在 python 中使用元组循环提取数据

python - 如何更改 PyCharm 中 IPython 控制台的启动首选项?

ipython - 你如何强制图形重绘 ipython 笔记本内联?