Standard Input, Output, Error

Standard Files

  • Found in the sys module
  • sys.stdin - Standard input
  • sys.stdout - Standard output
  • sys.stderr - Standard error

Many built-in functions use these

  • 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 files with other files if you want

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