Reputation: 8443
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
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
Reputation: 107598
It's a docstring. The only magic is that it ends up on the object as __doc__
.
Upvotes: 2