如何获得 PyGTK 方法的帮助?
在 pygtk 中,当我设置标签 mylabel = gtk.Label("Hello World!")
时,我可以通过 mylabel.get()
方法从中获取标签字符串。但在 python 解释器中我无法获取此方法的文档字符串:help(gtk.Label.get)
。有人知道为什么吗?
in pygtk when I set the label mylabel = gtk.Label("Hello World!")
I can get the string of label from it by mylabel.get()
method. but in python interpreter I can't get the docstring of this method: help(gtk.Label.get)
. Anyone know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为方法
gtk.Label.get
本身就是一个对象,并且具有一些属性。内置函数help
查找对象的__doc__
属性和其他一些字典以及对象的类并返回它们(格式化)。例如,您可以执行help(help)
! ;-) 所以help(gtk.Label.get)
返回方法/对象gtk.Label.get
的属性“__doc__
”并且通过类内省收集的一些其他信息。它不会为您提供有关gtk.Label
实例的实际值的帮助。Because the method
gtk.Label.get
is an object itself, and has some attributes. The builtin functionhelp
looks the__doc__
attribute and some other dictionaries of the object and the Class of the object up and returns them (formatted). You could do ahelp(help)
for example! ;-) sohelp(gtk.Label.get)
returns the attribute "__doc__
" of the method/objectgtk.Label.get
and some other information gathered by class-introspection. It doesn't give you a help on the actual values of yourgtk.Label
instance.我建议您使用ipython的动态对象信息 在解释器中使用某些库或调试某些代码时非常有用。
除此之外,如果您使用的是 Linux,安装 pygtk 文档包也非常有帮助,因为它与
devhelp
,一个可以让您轻松浏览和搜索文档的工具。I recommend you to use ipython's dynamic object information is quite helpful when playing with some library in the interpreter or when debugging some code.
Aside from that, if you're using linux, installing the
pygtk
documentation package is also very helpful because it integrates nicely withdevhelp
, a tool that lets you browse and search the documentation easily.@DonQuestion 可能已经回答了您想问的问题...但是,如果您真的只是想问为什么
help(gtk.Label.get)
不返回帮助..答案其实很简单:因为Label
对象中的get
方法在源代码中缺少文档字符串。 :)事实上,对
help
的调用不会生成错误,只是生成一个空答案。It might be that what you wanted to ask was answered by @DonQuestion already... however if you truly just wanted to ask why
help(gtk.Label.get)
doesn't return a help... the answer is actually very simple: because theget
method in theLabel
object lacks a docstring in the source code. :)In fact the call to
help
doesn't generate an error, just an empty answer.