[英]How do I show my argspec/docstring in bpython?
I'm just starting to use bpython, mainly because I really think it will help the office nubs a lot. 我刚刚开始使用bpython,主要是因为我真的认为它将极大地帮助办公室。 In bpython, it continually shows help text as you type. 在bpython中,它会在您键入时连续显示帮助文本。 For example 例如
>>> zip( ┌────────────────────────────────────────────────────────────────────────┐ │ zip: (seq1 [, seq2 [...]]) │ │ zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)] │ │ │ │ Return a list of tuples, where each tuple contains the i-th element │ │ from each of the argument sequences. The returned list is truncated │ │ in length to the length of the shortest argument sequence. │ └────────────────────────────────────────────────────────────────────────┘
This is great for the less educated (and even novice's like myself). 这对文化程度较低的人(甚至是像我这样的新手)来说都是很棒的。 However nothing shows up for my custom built functions. 但是,自定义构建的功能没有任何显示。 I thought maybe it was just displaying the docstring so I added docstrings to my functions. 我以为可能只是显示文档字符串,所以我在函数中添加了文档字符串。 Nothing changed. 没有改变。 Can someone explain to me what it is showing here and how I add it to my functions? 有人可以向我解释一下这里显示的内容以及如何将其添加到功能中吗?
EDIT: It must be some weird inheritance issue. 编辑:这一定是一些奇怪的继承问题。 This is being done with Django's custom managers. 这是通过Django的自定义管理器完成的。
class PublicationManager(models.Manager): """blarg""" def funct(arg): """foo""" pass class Publication(models.Model): objects = PublicationManager()
Typing PublicationManager.funct(
shows the docstring but Publication.objects.funct(
does not. I guess the nubs will have to figure it out for themselves. 键入PublicationManager.funct(
显示文档字符串,但Publication.objects.funct(
不会。我猜这些小块将不得不自己弄清楚。
Add your documentation string as the first line of your function: 将文档字符串添加为函数的第一行:
def funct():
"This function is self-documenting"
pass
Use triple quotes if it spans multiple lines: 如果跨多行,请使用三引号:
def funct():
"""
This function doesn't expect arguments
and returns zero.
"""
return 0
To get at the help in the repl use help(): 要获得repl的帮助,请使用help():
>>> help(funct)
Or to programmatically get at the docstring, use __doc__
: 或者以编程方式获取文档字符串,请使用__doc__
:
>>> print funct.__doc__
This function doesn't expect arguments
and returns zero.
>>>
Add it after your function line: 在您的功能行之后添加它:
def myFunc():
"""You Doc String Here
(even multiline)"""
pass
It's same for the classes: 这些类是相同的:
class MyClass():
"""Class Documentation"""
def __init__(self):
"""Function Documentation"""
pass
But for modules, you write docs at the top of the file: 但是对于模块,您可以在文件顶部编写文档:
#File: mymodule.py
"""Module Documentation"""
class Classes()...
def functions()...
Now if you import that in your main file: 现在,如果将其导入到主文件中:
import mymodule.py
print mymodule.__doc__
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.