Home >Backend Development >Python Tutorial >Detailed explanation of the usage of open function in python
Detailed explanation of the usage of open function in python
python open() function is used to open a file and create a file object. Only relevant methods can be called to read and write.
The syntax of the function is:
open(name[, mode[, buffering]])
Parameter description:
The basic value of the parameter Mode
r, w, and a are the basic modes for opening files, corresponding to read-only, write-only, Append mode; the four charactersb, t, and U are used in combination with the above file opening modes. Binary mode, text mode, read-write mode, and universal newline character are used in combination according to the actual situation.
Common mode value combinations
1、r或rt 默认模式,文本模式读 2、rb 二进制文件 3、w或wt 文本模式写,打开前文件存储被清空 4、wb 二进制写,文件存储同样被清空 5、a 追加模式,只能写在文件末尾 6、a+ 可读写模式,写只能写在文件末尾 7、w+ 可读写,与a+的区别是要清空文件内容 8、r+ 可读写,与a+的区别是可以写到文件任何位置Recommended tutorial: "
Python Tutorial"
The above is the detailed content of Detailed explanation of the usage of open function in python. For more information, please follow other related articles on the PHP Chinese website!