2

I want a list of the built-in function names of Python3, which I can get from help(__builtins__).

I thought grep the fetching results of help(__builtins__) would do.

Something like below in bash:

$ python3 -c "help(__builtins__)" | grep -E "^\s{4}[a-z]+\("

So, first I tried to capture the help function's results into a variable like below. But didn't work.

>>> result = help(__builtins__)
>>> print(result)
none

Since the "help()" function was intended for an interactive use, it launched the help page and couldn't get the output.

I googled with "python3 how do i get the output of help function" and referenced the below 2 article.

But didn't work for me.

>>> print(__builtins__.__doc__)
Built-in functions, exceptions, and other objects.

Noteworthy: None is the `nil' object; Ellipsis represents `...' in
slices.print(__builtins__.__doc__)

There's a good chance that I couldn't understand the answers of the above questions. But as a Python beginner, these didn't fully address my question.

Before doing grep and all, is there any way to get the help function's results into a variable rather than using exec?

Thanks in advance.

KEINOS
  • 1,050
  • 2
  • 13
  • 32
  • 2
    You can also use [`contextlib.redirect_stdout`](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout) context manager to capture the output to a file like object from [`help`](https://docs.python.org/3.6/library/functions.html#help) function. – Abdul Niyas P M Nov 06 '18 at 07:12
  • @AbdulNiyasPM Wow! thanks! `from contextlib import redirect_stdout` and using `with redirect_stdout(f):` I got the preferred same results as `$ python3 -c "help(__builtins__)"`. Now I can go forward to `grep` the results! I would like to answer my own how I ended, but it seems that my question is a duplicate and is locked. – KEINOS Nov 18 '18 at 11:35

0 Answers0