So here is what I am typing

>>> list = [1,2,3]
>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

The problem being that it literally prints "\n" instead of printing a new line, making more complicated doc strings almost impossible to read.

The same thing happens with all of the other built-in classes I have tried.

The version information I get from python when I open it is: Python 2.7.5 (default, Jul 16 2013, 14:23:29) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin

有帮助吗?

解决方案

That is because the list.__doc__ is a string.

When you just type list.__doc__ you will get the contents like this :

>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

However if you type print list.__doc__

>>> print list.__doc__
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

So the print function properly formats the string to include the linebreak.

Hope that helps :)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top