File Objects

open(filename [,mode])

  • Opens a file and returns a file object
  • By default, opens a file for reading.
  • File open modes
     "r"      Open for reading
     "w"      Open for writing (truncating to zero length)
     "a"      Open for append
     "r+"     Open for read/write (updates)
     "w+"     Open for read/write (with truncation to zero length)
     

Notes

  • A 'b' may be appended to the mode to indicate binary data.
  • This is required for portability to Windows.
  • "+" modes allow random-access updates to the file.
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 32
July 17, 2000, beazley@cs.uchicago.edu
>>>