canadadry
canadadry

Reputation: 8443

What does bare strings in the body of a class definition mean?

Here is a snippet of code from django.core.exceptions:

class MiddlewareNotUsed(Exception):
    "This middleware is not used in this server configuration"
    pass

Is the bare string in the body of the class a mere literal for documentation ? Or does it perform some magic ?

Upvotes: 2

Views: 413

Answers (3)

UncleZeiv
UncleZeiv

Reputation: 18488

It's a doc string:

A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object.

All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings. Public methods (including the __init__ constructor) should also have docstrings. A package may be documented in the module docstring of the __init__.py file in the package directory.

Upvotes: 8

mouad
mouad

Reputation: 70021

It's called a docstring.

Upvotes: 1

Jochen Ritzel
Jochen Ritzel

Reputation: 107598

It's a docstring. The only magic is that it ends up on the object as __doc__.

Upvotes: 2

Related Questions