Get dosctring without import

Ben Finney ben+python at
Sat Feb 27 00:58:54 CET 2010

Joan Miller <peloko45 at> writes:

> On 26 feb, 12:35, Ben Finney <ben+pyt... at> wrote:
> > A common convention is to have a ‘README’ text file, written in
> > reStructuredText for rendering to various output formats as part of
> > the documentation. You could then have the ‘’ program read
> > the contents of that file and use it (or a slice of it) for the
> > package description.
> I get the 'README.txt' file to get the long description but I use the
> docstring because each package should include a short desciption about
> it.

I keep both in the same file:

===== README =====
FooBar, a library for spangulation.

The FooBar library provides thribbles which can be
easily frobnicated for spangulation in a sntandard manner.

Other spangulation libraries are far less weebly than this
one, which is the choice of discerning grognards everywhere.

Then, the description fields are derived by splitting the file's
contents on the first paragraph break:

from distutils.core import setup

readme_file = open("README")

short_description, long_description = (
    for d in'\n\n', 1))

    # …
    # …

 \      “Some forms of reality are so horrible we refuse to face them, |
  `\     unless we are trapped into it by comedy. To label any subject |
_o__)        unsuitable for comedy is to admit defeat.” —Peter Sellers |
Ben Finney

More information about the Python-list mailing list