Why does “pydoc -g” at the command prompt bring up python libraries installed on my system, but I can't do that command from the Python Interpreter?

StackOverflow https://stackoverflow.com/questions/12439896

  •  02-07-2021
  •  | 
  •  

문제

Why does typing:

  [user_name]$ pydoc -g

in iTerm (the command prompt) bring up the python index of modules on my computer, but I can't run that line from the Python Interpreter?

Thanks!

도움이 되었습니까?

해결책

pydoc is a command line program /usr/bin/pydoc. In the Python Interpreter you can only access python classes and modules.

If you want to do the same from the interpreter, you can import the pydoc module and then call pydoc.gui().

다른 팁

Because Pydoc is not a call to some feature built into the Python standard library. Pydoc is an external program, that runs functions on Python code. It works on iTerm because iTerm can call such programs. For instance, you should be able to call programs like cat, grep and vim from iTerm because it works with these external programs. But these are not available to Python through its interpreter.

>>> import subprocess
>>> subprocess.Popen("pydoc -g", stdout=subprocess.PIPE, shell=True).stdout.read()

The above will call OS executables

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top