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. In bpython, it continually shows help text as you type. 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 argum开发者_StackOverflow社区ent 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.
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.
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():
>>> help(funct)
Or to programmatically get at the docstring, use __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__
精彩评论