Python — How to get help text help() into a variable?

How to get the text in a variable ?
import random
a= help(random.sample)
print(a) # - now None
June 7th 19 at 14:23
3 answers
June 7th 19 at 14:25
Solution
a = random.sample.__doc__

UPDATE:
I was curious as to intercept the output, and I found a solution:
from io import StringIO
import random
import sys

class OutputInterceptor(list):
 def __enter__(self):
 self._stdout = sys.stdout
 sys.stdout = self._stringio = StringIO()
 return self

 def __exit__(self, *args):
self.extend(self._stringio.getvalue().splitlines())
 del self._stringio
 sys.stdout = self._stdout

with OutputInterceptor() as output:
help(random.sample)

print('\n'.join(output))
print(random.sample.__doc__)
print(help(random.sample))
only here the texts of the different issues - ivah_OKeef commented on June 7th 19 at 14:28
one only difference can be - in the second case, at the end of the text will be None. - samir39 commented on June 7th 19 at 14:31
5a9b0218b184a902177033.png - ivah_OKeef commented on June 7th 19 at 14:34
That's the way it should be - ivah_OKeef commented on June 7th 19 at 14:37
, 5a9b03cbb0588755997846.png

The part labeled number 2 is taken from the attribute __doc__. And the part marked with 1 is formed so. - samir39 commented on June 7th 19 at 14:40
Thank you. Very clearly pointed out here - at once it is clear now :-) - ivah_OKeef commented on June 7th 19 at 14:43
June 7th 19 at 14:27
it is sufficient to read the documentation https://docs.python.org/3.6/library/functions.html#help
June 7th 19 at 14:29
Bravo!!!! I suspect that this can be done in python with connection sys :-)

Find more questions by tags Python