Standard Input, Output, and Error

Standard Files

  • sys.stdin - Standard input
  • sys.stdout - Standard output
  • sys.stderr - Standard error

These are used by several built-in functions

  • print outputs to sys.stdout
  • input() and raw_input() read from sys.stdin
     s = raw_input("type a command : ")
     print "You typed ", s 
  • Error messages and the interactive prompts go to sys.stderr

You can replace these with other files if you want

     import sys
     sys.stdout = open("output","w")
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 35
July 17, 2000, beazley@cs.uchicago.edu
>>>