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
  •  | 
  •  

Question

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!

Était-ce utile?

La solution

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().

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top