Python文件操作
Posted 3尺尘沙
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python文件操作相关的知识,希望对你有一定的参考价值。
open(...)
open(file, mode=\'r\', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None) -> file object
Open file and return a stream. Raise IOError upon failure.
========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
\'r\' open for reading (default)
\'w\' open for writing, truncating the file first
\'x\' create a new file and open it for writing
\'a\' open for writing, appending to the end of the file if it exists
\'b\' binary mode
\'t\' text mode (default)
\'+\' open a disk file for updating (reading and writing)
\'U\' universal newline mode (deprecated)
========= ===============================================================
The default mode is \'rt\' (open for reading text). For binary random access, the mode \'w+b\' opens and truncates the file to 0 bytes, while \'r+b\' opens the file without truncation.
The \'x\' mode implies \'w\' and raises an `FileExistsError` if the file already exists.
文件的打开模式:
文件的对象方法:
以上是关于Python文件操作的主要内容,如果未能解决你的问题,请参考以下文章