# python文件读写的几种方式

### 前言

Python读取文件的方式有多种，但每种方式都有各自的不同的特点，在使用的时候需要注意这细节的不同。

### 文件读取

Read at most size uncompressed bytes, returned as a string. If the size argument is negative or omitted, read until EOF is reached.

API说明如下：

Return the next line from the file, as a string, retaining newline. A non-negative size argument limits the maximum number of bytes to return (an incomplete line may be returned then). Return an empty string at EOF.

readline方法通常用法如下所示：

readlines在处理文件时是非常有用的方法。API文档说明如下：

Return a list of lines read. The optional size argument, if given, is an approximate bound on the total number of bytes in the lines returned.