Working with Files [June 5, 2011, 9:03 p.m.]
An important part of programming is knowing how to work directly with files. Lets review the following Pythonic tools for working with files:
- open()
- read()
- readlines()
- write()
- seek()
- close()
- the Pickle module
open()
The open() function takes a filename and path as input and returns a file object.
open('/path/to/file', 'r')
The second parameter for the open() function is the file permission mode and is entered in the form of read (r), write (w), or append (a). If no mode parameter is passed, the mode defaults to read.
Learning Resources
- Chapter 7 (Slides, Printable Slides, Lecture Audio)
Python Docs