views:

126

answers:

2

In Windows, if I open a command prompt, start python, and inspect something using its __doc__ property, it doesn't display correctly. Instead of the lines being separated, I see one continuous string with the newline character every once and a while.

Is there a way to make it appear correctly?

Here's an example of what I see:

>>> hashlib.__doc__

'hashlib module - A common interface to many hash functions.\n\nnew(name, string=\'\') - returns a n ew hash object implementing the\n given hash function; initializing the hash\n using the given string data.\n\nNamed constructor functions are also availabl e, these are much faster\nthan using new():\n\nmd5(), sha1(), sha224(), sha256(), sha384(), and sha5 12()\n\nMore algorithms may be available on your platform but the above are\nguaranteed to exist.\n\ nNOTE: If you want the adler32 or crc32 hash functions they are available in\nthe zlib module.\n\nCh

+2  A: 

try

>>> print hashlib.__doc__

or (v3)

>>> print(hashlib.__doc__)
gimel
What gimel said goes for any string with a newline in it. I know this won't show up right in a comment, but:>>> "\n".join(["hello world", "goodbye world"]);'hello world\ngoodbye world'>>> print _;hello worldgoodbye world
Mark Rushakoff
+3  A: 

Rather than pulling __doc__ yourself, try this:

>>> help(hashlib)

It will give you a nicely formatted summary of the module, including (but not limited to) the docstring.

Ned Batchelder
Thanks--I'm sure I'll use this in addition to the solution gimel gave.
Jim