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.
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
You might find it more helpful to use (for example) help(divmod)
instead of divmod.__doc__
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With