Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
a = random.sample.__doc__
I was curious about how 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))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question