码迷,mamicode.com
首页 > 编程语言 > 详细

Python文件操作

时间:2016-08-26 01:20:02      阅读:263      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!