0

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!

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
user1590499
  • 933
  • 3
  • 10
  • 17

3 Answers3

2

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

Hans Then
  • 10,935
  • 3
  • 32
  • 51
  • Thanks man. Just to clarify, how is the 'pydoc' module related to the 'pydoc' command line program? – user1590499 Sep 15 '12 at 18:29
  • The pydoc command line program is a small python script. It imports pydoc and then calls pydoc.gui() :-) – Hans Then Sep 15 '12 at 18:32
  • cool! I see, so when I am in the interpreter and type 'import pydoc' and then 'pydoc.gui()' that's the same thing as calling the '$pydoc -g' script from the command line. If you don't mind my asking, what other python scripts are inherently available from the command line? – user1590499 Sep 15 '12 at 18:35
  • `pydoc` the program is a small driver program which imports `pydoc` (the module). Try `cat /usr/bin/pydoc2.6` to see the program (note that `/usr/bin/pydoc` itself may be a version-select script). – nneonneo Sep 15 '12 at 18:36
1

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.

mjgpy3
  • 8,597
  • 5
  • 30
  • 51
1
>>> import subprocess
>>> subprocess.Popen("pydoc -g", stdout=subprocess.PIPE, shell=True).stdout.read()

The above will call OS executables

user1655481
  • 376
  • 1
  • 10
  • Thanks! Out of curiosity, I use .exe files all the time, but what's a good description of what OS executables are? – user1590499 Sep 15 '12 at 18:31
  • that hard :) , I think I have used a wrong term/less generic term...The above command will cover all the files that execute on OS default shell. – user1655481 Sep 15 '12 at 18:37