File Methods

The following methods may be applied to a file object

     f.read([n])              Read at most n bytes
     f.readline()             Read a single line of input
     f.readlines()            Read all input lines
     f.write(s)               Write string s
     f.writelines(l)          Write all strings in list l.
     f.close()                Close the file
     f.tell()                 Return the current file pointer
     f.seek(offset [,where])  Seek to a new position
     f.isatty()               Returns 1 if an interactive terminal
     f.flush()                Flush output buffers
     f.truncate([n])          Truncate file to at most n bytes
     f.fileno()               Return integer file descriptor

Notes

  • Line-oriented operations are aware of newline differences (Unix vs. Windows)
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 115
July 17, 2000, beazley@cs.uchicago.edu
>>>