Files

open(filename [, mode])

  • Opens a file and returns a file object.
  • Mode is one of the following
     "r"   - Open for reading (the default)
     "w"   - Open for writing (destroys old contents if any)
     "a"   - Open for append
     "r+"  - Open for read/write (updates)
     "w+"  - Open for read/write (destroys old contents first).
  • An optional "b" may be appended to specify binary data.
  • Example:
     f = open("foo")       # Open for reading
     g = open("bar","w")   # Open for writing
     h = open("spam","rb") # Open for reading (binary)
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 114
July 17, 2000, beazley@cs.uchicago.edu
>>>