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

Extract all docstrings (__doc__) from my Django files

I have a project in Django and I write docstrings in my modules, classes and functions. But I need a way to extract all __doc__ from there automatically. Like "python manage.py collectstatic" but for .__doc__ instances for all .py codes. Something…
pydev
  • 1
  • 2
0
votes
1 answer

How to get the user Input in Pandas for a particular column from the dataframe python3

I'm using PANDAS Dataframe to get the data from CSV file and opting to choose the desired column data which is working fine. However, in the hostData Dataframe i'm looking specially for (data['Safe']=='KDS-PDC-DEFAULT-UNIX-ROOT') portion so, as i…
Karn Kumar
  • 8,518
  • 3
  • 27
  • 53
0
votes
1 answer

Python equivelent to PHPDoc Blocks?

I am new to Python coming from PHP, I know Python has Docstrings, but how can I do this on class variables? Let's say in PHP I have: class Animal { /** * @var Noise */ public $noise } Now how would I implement this is python?…
superdee
  • 637
  • 10
  • 23
0
votes
3 answers

Python function/method docstring variables

Let's say I what to write a docstring for the code bellow: def some_thing_cool(age, name): better_age = age - 20 cooler_name = name + 'awesome' bday_list = ['cake', 'balloons'] return bday_list Would it be like this: def…
0
votes
0 answers

How to create Sphinx index from a specific or custom docstring element?

Is it possible to create an index in Sphinx which is created by specific (or custom) elements in the docstring? For example, I have the following function and would like to have Sphinx to create an index from the field "Command Reference". Is this…
sven
  • 11
  • 3
0
votes
1 answer

Django swagger special character escape documentation

I use django and swagger. I write doc string in my django function like this : /?first_name__icontains=saeed&age__gte=20. But swagger show them like this how can I escape characters like & in django and swagger? Edit: My code in docstring of a…
mastisa
  • 1,875
  • 3
  • 21
  • 39
0
votes
0 answers

Getting docstring in QPython3

So far all the modules I tested (all in the standard Python library) do not print anything when I run __doc__. help() works, but I am after __doc__ specifically. I have tried this without…
Xantium
  • 11,201
  • 10
  • 62
  • 89
0
votes
2 answers

TextMate scope for triple quoted Python docstrings

I'm currently setting up VS Code for Python development. I'd like to have triple-quoted docstrings highlighted as comments, not as strings, i.e. grey instead of light green in this picture: I know that I can adjust this in the TextMate rules for…
gmolau
  • 2,815
  • 1
  • 22
  • 45
0
votes
1 answer

Docstring - Usage of parameter name and type of in python

I've written some classes in Python and I have written docstrings for them like this: class DB: def execute_and_return(self, sql): """Execute the query and returns the result as a list of list Parameters ---------- …
axel_ande
  • 359
  • 1
  • 4
  • 20
0
votes
0 answers

Check that a Python project is properly documented

I have a bunch of Python v3.6 projects. I am using codestyle to check that they are PEP8 compliant. Is there a way to use codestyle (or any other tool) to check that all functions, classes and methods in my modules are documented (i.e., have an…
0
votes
1 answer

how to display unicode docstring by calling help() on idle

When a function is defined in python, triple quotes represent docstring. But Asian characters used in docstring are not properly displayed on IDLE for MacOS. They are displayed as a unicode string like '\uc778\uc0ac\ud569\ub2c8\ub2e4'. On Windows…
albert
  • 1
  • 1
0
votes
1 answer

Properly document a constructor passed as parameter

I'm trying to figure out what is the properly way to document a function that receives a class constructor as parameter . I'm using Google style docstring. Example: class MyClass: def __init__(self): ... def my_func(param1,…
0
votes
1 answer

docstring(myClass.aProperty) does not return the docstring for aproperty

Below is a sketch of a class I want to document. My first wish is to get short help from within Jupyter. These help calls work as I expected: help(thermo): showing everything (class, methods and properties) help(thermo.select): showing the select…
user5852223
0
votes
0 answers

Python: Unittest testing based on Docstring?

I am new to using unittest for testing my modules. Usually docstrings already contain a lot of useful info such as the datatypes expected by a function or the datatype of the return value. E.g. def myFunc(parmA,paramB): """ This function is…
Suppenkasper
  • 845
  • 4
  • 10
  • 29
0
votes
1 answer

Python: doctest accent issue

I'm a Python beginner, for school, and I am a little pernickety. My teacher wants me to write a function, returning a sentence with an accent, "print()" show me the good characters, with the accent, but the doctest doesn't. Here is my code : def…
Sidimoth
  • 1
  • 1