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
1 answer

Find author of python file from docstring

I'm trying to write a program which has a function that finds and prints the author of a file by looking for the Author string in the docstring. I've managed to get the code below to print the author of a file that has the author string followed by…
jevans
  • 399
  • 1
  • 3
  • 11
0
votes
1 answer

How to add docstrings to a module that I can't write to

I have a module to which additional functions are programmatically getting written to. I.e.: def fun1(): # function written on 27.02.13 ... def fun2(): # function written on 28.02.13 ... I would like to add docstrings to the module…
MattSchmatt
  • 850
  • 8
  • 18
0
votes
1 answer

how to make function docstring automatically updated according to another function in python?

Suppose I have some functions (say B1,B2,B3,etc...) which call the same function A, I want to put in docstrings of B1,B2,B3 some texts explaining parameter that are used by function A, and these are already explained in the docstring of function A.…
wiswit
  • 5,599
  • 7
  • 30
  • 32
0
votes
1 answer

IronPython: How to obtain XML documentation strings from .NET assemblies

How do you get the XML documentation strings from .NET assemblies using IronPython? Using '_doc_' doesn't seem to be the way. MessageBox.Show(Label().Bottom.__doc__) returns "Represents a 32bit signed integer." How do I get the actual doc string,…
John_Sheares
  • 1,404
  • 2
  • 21
  • 34
0
votes
0 answers

Inheritance: method getting its doc string from the parent class

I was playing with doc strings and I ended up with this code: import inspect class InheritedDoc(object): """ Decorator to find docstrings from parent classes of the method class. Decorator are interpreted on the import and not …
Jordi Riera
  • 101
  • 1
  • 5
-1
votes
1 answer

How to fix "Unexpected section title"?

This docstring: """ Returns ------- out: int Output. Bad title --------- Text. """ produces: C:\module.py:docstring of my_pkg.module.func:5: CRITICAL: Unexpected section title. Bad title --------- Can I make it respect Bad title, or at…
-1
votes
1 answer

PEP8 best docstring practice when function has multiple different return

I have the following function: def eg_fun(eg:int): """example function """ if eg > 2: return 2, 4 else: return 'no', None In the function definition how I can put different returning Tuple? If I would have a…
Will
  • 1,619
  • 5
  • 23
-1
votes
2 answers

How to add link in Python docstring?

I have a function in python 3.x def foo(): """Lorem ipsum for more info, see here"" I want to add a hyperlink to 'here' to point to a website. How can I do that without installing external plugin?
-1
votes
1 answer

Quantify docstrings in python project

Is there anyway to quantify the percentage of docstrings in a python project, concerning all modules, function, classes, methods, etc.? I didn't found any package or linter offering that.
Henrique Branco
  • 1,778
  • 1
  • 13
  • 40
-1
votes
1 answer

How to write docstrings for functions written in functional paradigm using pipetools

I use pipetools to write functions, which is a "functional plumbing library for python". An example function (from their docs): pyfiles_by_length = (pipe | os.listdir | where(X.endswith('.py')) | sort_by(len).descending | (enumerate,…
-1
votes
2 answers

Docstring at End

I have written a simple code in Python . I read that if we write docstring at the end of code , then it is printed as usual. My code is a = 'good' b= "boy" print(a+ b) """ this will be a good example """ The output is goodboy However I suppose…
Brijesh
  • 35
  • 6
-1
votes
1 answer

Including a docstring in another docstring

Problem: I want to use one docstring in another docstring. Suppose I have the following snippet: def window(dimensions: tuple): ''' Function to create an app window and return it PARAMETERS ---------- dimensions : tuple …
Jaideep Shekhar
  • 808
  • 2
  • 7
  • 21
-1
votes
2 answers

Python docstring about the type of object being returned

class Foo: def __init__(self, bar): self.bar = bar def get_new_foo(self, new_bar): return type(self)([self.bar, new_bar]) #How should it be documented? If get_new_foo gets called from a derived class, then it would return…
user6037143
  • 516
  • 5
  • 20
-1
votes
1 answer

Custom Docstrings in Python

How would create a custom docstring in python? Would you just say __nameofdocstring__ or is there something else you should do? Is it possible to create a new docstring for a certain .py file? I want to write __notes__ = "blah blah blah", but just…
-1
votes
1 answer

Python 2.7, trouble printing docstrings (doc comments) "function has no attribute _doc_" error

I'm working on LPTHW ex 41, where we modify a bunch of print statements to use a docstring style and then use a runner to print them. The code originally was like this: Function() Print "Several lines of printed material" Revised, the functions…
themagicbean
  • 156
  • 14
1 2 3
49
50