Standard input, output, and error

stdin

stdin is a file-like object with a read method:

def openAnything(source):
    if source == "-":
        import sys
        return sys.stdin

    # try to open with urllib (if source is http, ftp, or file URL)
    import urllib
    try:

stdout

stdout is a file-like object; calling its write function will print out whatever string you give it:

import sys
sys.stdout.write('Dive in')