12

So, when I try to print help/info of Python functions function.__doc__, the console output instead of printing a newline when \n occurs in the doc string, prints \n. Can anyone help me with disabling/helping out with this?

This is my output:

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

What I would like the output to be:

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

P.S: I have tried this on OS X, Ubuntu with Python 2.7.

3 Answers 3

25

Looks like you inspected the object in the interactive shell, not printed it. If you mean print, write it.

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

In python 3.x print is an ordinary function, so you have to use (). The following (recommended) will work in both 2.x and 3.x:

>>> from __future__ import print_function >>> print("abc\n123") abc 123 
Sign up to request clarification or add additional context in comments.

2 Comments

Yes. So from what I understand, to 'unsee' the '\n', I should use the print instead of just typing [function].__doc__ ?
Yes. It will also leave off the quotes.
3

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

Comments

1
In [6]: print divmod.__doc__ divmod(x, y) -> (div, mod) Return the tuple ((x-x%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 ((x-x%y)/y, x%y). Invariant: div*y + mod == x. 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.