Mastering Python for Networking and Security
上QQ阅读APP看书,第一时间看更新

File methods

These are the functions that can be used on a file object.

  • file.write(string): Prints a string to a file, there is no return.
  • file.read([bufsize]): Reads up to “bufsize” number of bytes from the file. If run without the buffer size option, reads the entire file.
  • file.readline([bufsize]): Reads one line from the file (keeps the newline).
  • file.close(): Closes the file and destroys the file object. Python will do this automatically, but it’s still good practice when you’re done with a file.