首页 > 编程语言 > 详细

Python文件操作

时间:2016-08-26 01:17:03      阅读:344      评论:0      收藏:0      [点我收藏+]

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文件操作

原文:http://www.cnblogs.com/shiddong/p/5808745.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!