How to create a docstring for a module?

Chris Rebert clp2 at rebertia.com
Sun Dec 6 16:06:05 EST 2009


On Sun, Dec 6, 2009 at 12:34 PM, Dr. Phillip M. Feldman
<pfeldman at verizon.net> wrote:
> OK.  I was able to reproduce the problem.  My difficulty was that the command
> that I issued initially was "from xyz import *" rather than just "import
> xyz".  If I say "import xyz", then the docstring is defined; if I say "from
> xyz import *", it isn't.  I'm not sure whether this is a bug or expected
> behavior.

Expected behavior. If you `from foo import bar`, the name `foo` won't
be bound, so needless to say you won't be able to access its docstring
foo.__doc__.

$ ipython
Python 2.6.2 (r262:71600, Nov  5 2009, 15:03:16)
Type "copyright", "credits" or "license" for more information.

IPython 0.10 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object'. ?object also works, ?? prints more.

In [1]: ?pickle
Object `pickle` not found.

In [2]: from pickle import *

In [3]: ?pickle
Object `pickle` not found.

In [4]: pickle.__doc__
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)

/Users/chris/<ipython console> in <module>()

NameError: name 'pickle' is not defined

In [5]: import pickle

In [6]: ?pickle

<shows the documentation>

In [7]: pickle.__doc__
Out[7]: 'Create portable serialized representations of Python
objects.\n\nSee module cPickle for a (much) faster
implementation.\nSee module copy_reg for a mechanism for registering
custom picklers.\nSee module pickletools source for extensive
comments.\n\nClasses:\n\n    Pickler\n    Unpickler\n\nFunctions:\n\n
  dump(object, file)\n    dumps(object) -> string\n    load(file) ->
object\n    loads(string) -> object\n\nMisc variables:\n\n
__version__\n    format_version\n    compatible_formats\n\n'


Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list