How can I print the Python help page directly to stdout?
I am trying to write a Unix script that will allow me to print the Python help page for a given module. My code so far is below:
#!/usr/bin/env python if __name__ == "__main__": import sys if sys.argv.endswith(".py"): __import__(sys.argv[:-3]) help(sys.argv[:-3]) else: __import__(sys.argv) help(sys.argv)
It works almost the way I want it to. Calling it on a module brings up the help page in a buffer, similar to calling
. (In other words, it
works exactly the same as when used in the interpreter.)
I would like to get rid of the buffer and print directly to stdout so that I can use the command with other Unix commands. I am wondering if there is a way to do this, and if so, how?
source to share