简体   繁体   English

IPython中奇怪的模块自动完成行为

[英]Strange module auto complete behavior in IPython

在此处输入图片说明 See what I mean? 明白了吗? At first it showed only RB and absolute_import as choices. 最初,它仅显示RBabsolute_import作为选择。 STILL I was able to import Gtk . 还可以导入Gtk After that it showed a couple of more options. 之后,它显示了更多其他选择。 Still isn't a complete list of modules. 仍然不是模块的完整列表。 If I import some other module (which I know of from the docs), then it appears in the list. 如果导入其他模块(我从文档中知道),则它将显示在列表中。

(I posted a similar problem previously but I wasn't able to explain it sufficiently well so I'm posting it again with better details) (我以前曾发布过类似的问题,但我无法很好地解释它,因此我将再次发布其详细信息)

Autocompletion try to determine the possible value of what you ask. 自动补全功能尝试确定您要求的可能值。 gi.repository is probably defining stuff at import time so you cannot get everything right before actually importing it. gi.repository可能在导入时定义了内容,因此您在实际导入之前无法正确处理所有内容。

Like if you overwrote the __getattr__ method of an object, you could make it respond to an arbitrary amount of key without being able to list them. 就像您重写对象的__getattr__方法一样,您可以使它响应任意数量的键而无法列出它们。

To know the exact reason you should dive into the code of gi.repository (PyGI itself seem deprecated for 3 Years, replaced by pygobject), which from a quick readthrough is a completly dynamic binding of GObject that really build itself at import time by inspecting Gobject. 要知道确切的原因,您应该深入研究gi.repository代码(PyGI似乎已被弃用3年,由pygobject取代),通过快速通读,它是GObject的完全动态绑定,它实际上是在导入时通过检查来构建的Gobject。

So I wouldn't be surprise that such an module have weird behavior at tab-completion. 因此,这样的模块在制表符完成时具有怪异的行为也就不足为奇了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM