open
(name[, mode[, buffering]])
打开一个文件,将该文件作为文件对象返回,如果文件无法打开,则返回IOError。
name is the file name to be opened
mode is a string indicating how the file is to be opened.The most commonly-used values of mode are 'r'
for reading, 'w'
for writing, and 'a'
for appending. when opening a binary file, you should append 'b'
to the mode value to open the file in binary mode
The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size (in bytes). A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used.