Python newline display in console

So, when I try to print help / information about Python function.__doc__ , the console output, instead of printing a new line when \n appears in the document line, prints \n . Can someone help me disable / help with this?

This is my conclusion:

 'divmod(x, y) -> (div, mod)\n\nReturn the tuple ((xx%y)/y, x%y). Invariant: div*y + mod == x.' 

I would like the result to be as follows:

  'divmod(x, y) -> (div, mod) Return the tuple ((xx%y)/y, x%y). Invariant: div*y + mod == x.' 

PS: I tried this on OS X, Ubuntu with Python 2.7.

+7
source share
3 answers

It looks like you checked the object in an interactive shell, and did not print it. If you mean print, write it.

 >>> "abc\n123" "abc\n123" >>> print "abc\n123" abc 123 

In python 3.x, print is a regular function, so you need to use (). The following (recommended) will work in both 2.x and 3.x versions:

 >>> from __future__ import print_function >>> print("abc\n123") abc 123 
+16
source

You might find it helpful to use (for example) help(divmod) instead of divmod.__doc__ .

+3
source
 In [6]: print divmod.__doc__ divmod(x, y) -> (div, mod) Return the tuple ((xx%y)/y, x%y). Invariant: div*y + mod == x. 

but I suggest you use

 In [8]: help(divmod) 

or in IPYTHON

 In [9]: divmod? Type: builtin_function_or_method Base Class: <type 'builtin_function_or_method'> String Form:<built-in function divmod> Namespace: Python builtin Docstring: divmod(x, y) -> (div, mod) Return the tuple ((xx%y)/y, x%y). Invariant: div*y + mod == x. 
+1
source

All Articles