Get dosctring without import

Ben Finney ben+python at
Fri Feb 26 11:51:05 CET 2010

Joan Miller <peloko45 at> writes:

> When a package is imported, it gets the dosctring to store it in
> *__doc__*.

Joan, in this message and numerous others you've been following the
widespread convention of using asterisks ‘*’ to surround text you want
to emphasise.

Normally that's good, but in a programming-language context (or any
other where asterisks have a separate established meaning), it's not a
good idea. In many cases, asterisks signify “match any number of
arbitrary characters at this position”, which gives a rather different
meaning to what you're writing.

You might be better off using quotes (like '__doc__' or ‘__doc__’), or
the reStructuredText syntax for demarcating a special element, backticks
(like `__doc__`). Even they need to be used with care, though, because
they also have specific established meanings (except the typographical
quotes, which is why I use them).

I hope that helps.

> Does that funcion is built in python? because I would want use it to
> get the docstring without import a package

Why is it you want to do this? Modules should not have unwanted side
effects when imported; if you can't import the module without invoking
those unwanted side effects, the module is poorly written.

That's not to say that such poorly-written modules don't exist. What is
the situation? Perhaps there's a better solution.

 \      “Earth gets its price for what Earth gives us.” —James Russell |
  `\                                                            Lowell |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list