Questions tagged [docstring]

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

A docstring is a string that occurs as the first statement in a module, function, class, or method definition, and is used to document the object in which it occurs.

For example, this Python module:

"""shibboleth.py - answer a common interview question with style and grace."""

DEFAULTS = (
    (3, "Fizz"),
    (5, "Buzz"),
)


def fizzbuzz(limit=15, sep=" ", **kwargs):
    """Print from 1 to `limit`, replacing as in the childhood game."""
    transform = sorted((v, k) for k, v in kwargs.items()) or DEFAULTS
    for number in range(1, limit + 1):
        matches = (word for factor, word in transform if number % factor == 0)
        print(sep.join(matches) or number)

... contains two docstrings: a module-level docstring which contains the filename of the module and a brief description of its purpose, and a function-level docstring which describes the behaviour of the function in which it occurs.

Conventions for writing Python docstrings can be found in PEP 257: Docstring Conventions.

Info on docstrings in other languages than Python can be found on Wikipedia.

745 questions
0
votes
2 answers

PyDev doesn't show docstring

I'm working with PyDev on Eclipse and for some reason it doesn't show docstring when I'm hovering over a function. What also doesn't work, is to jump into a function when pressing F3. Both features work on the computer of my coworker. We tried it…
Burschken
  • 77
  • 11
0
votes
0 answers

Generate php docstring

I recently inherited an existing PHP codebase. The code adheres to PSR-2, but no a single phpdoc comment is present. What i have tried : i ran PHPCS with PEAR standard and i got a list of every comment that would be required. The problem: i have to…
nipil
  • 76
  • 1
  • 8
0
votes
1 answer

python get docstring from terminal using option

Let us say I have a file myfile.py """ long documentation of myfile.py ... """ # tons of stuf # this include some functions and their documentation and I would like to do bash $ python myfile.py -h such that it displays all the documentation but…
Tsathoggua
  • 799
  • 6
  • 14
0
votes
1 answer

google apps script: Create a spreadsheet where newly created doc IDs appear

Be gently, very noob at this. So I've just replaced a guy who got a promotion and I am a primary teacher who has only really vaguely dabbled with this. I have successfully created a script that will do a lot of the things I need (so now looking to…
0
votes
1 answer

Can't render python reST format docstring

I was studying a python framework, scrapy and I learned that it uses a style of docstring as below class CrawlerRunner(__builtin__.object) | This is a convenient helper class that keeps track of, manages and runs | crawlers inside an already…
user5538922
0
votes
2 answers

How to force help to use overridden __doc__

Let's assume I define a simple class Foo: class Foo(object): """This is Foo""" def __init__(self, label): self.__doc__ = "This is {} Foo".format(label) def __call(self, *args): ... # Some behavior which depends on the…
0
votes
2 answers

Python. Hint for variable

I'm using PyCharm as editor. For example, I have next function: def get_instance(): # method without doc sctring in some module # returns instance of MyClass return some_var And I have second file which calls get_instance(): var =…
Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
0
votes
2 answers

reStructuredText link in Python

If I have the following function in Python: def _add_parameter(self, a): # do something And I want to add a docstring to link to the above function using reStructuredText, I just need to add an underscore at the end of the function name like…
Sajid
  • 97
  • 2
  • 7
0
votes
1 answer

The meaning of Epydoc notations, L{ClassName} C{int}?

While reading some others' code, I came across this type of docstring @param reporter: A L{Reporter} instance, where ... and figured out after some search that it's Epydoc. But what does these notations such as L{ClassName?} and C{type?} mean?
Taejoon Byun
  • 101
  • 1
  • 4
0
votes
1 answer

Keep lines inside docstrings within 79 character limit

I am writing some doctests in my module. Relevant code def foo(): """ Populates the database with 'VALUES' >>> import sqlite3 >>> con = sqlite3.connect('test.db') >>> cur = con.cursor() >>> cur.execute('select * from…
Tasdik Rahman
  • 2,160
  • 1
  • 25
  • 37
0
votes
1 answer

how to specifically use the global docstring?

I want to use the global doctstring in my command help. This a working example: """ This is a global description. Usage: Use it like so:: $ python my_fancy_script """ from __future__ import absolute_import from __future__…
LarsVegas
  • 6,522
  • 10
  • 43
  • 67
0
votes
1 answer

Python - How not to sort pydoc output in alphabetic order

pydoc's output sorts the results (methods and their docstrings) based on the alphabetical order. This is good, but I want to stay on top of what is new. When I add a new method in my module, I add it as the first method, so every time I add a new…
gixxer
  • 814
  • 1
  • 10
  • 25
0
votes
1 answer

Java docstringes through private variable in class

public static class cls{ private String text; public String getText(){ return text; } } Is it possible to show the text variable in the docstrings of of cls in Java without having to copypaste the content?
Christian
  • 25,249
  • 40
  • 134
  • 225
0
votes
1 answer

Doctest: Splitting a docstring for Python function call over multiple lines

I am wondering if there is a way to split function calls over multiple lines for doctest. E.g., for something like >>> result = some_func(some_param=1, another_param=4, a_third_param='super_long_string') I tried >>> result =…
user2489252
0
votes
1 answer

Convert scipy docstrings (reST) to HTML using docutils

I'm designing a filter design GUI and would like to display docstrings from Python's scipy.signal in a QTextBrowser, requiring HTML format. I think docutils should do the job for me and I tried from docutils.core import publish_string from…
Chipmuenk
  • 607
  • 1
  • 7
  • 22