python之路 之open
2016-05-02 19:37
525 查看
一、open:文件打开操作
打开文件的模式有:
r:只读,默认(文件不存在则报错)
w:只写(文件不存在则自动创建)
a:追加(文件不存在则自动创建)
'+'表示可同时读写文件
r+:读写(可读,可写,可追加),可读可写,不会清空文件
w+:写读,可使用read系列
a+:同a
"U"表示在读取时,可以将 \r \n \r\n自动转换成 \n (与 r 或 r+ 模式同使用)
rU
r+U
b:处理进制文件(如FTP发送上传镜像ISO文件,linux可忽略,WINDOWS处理二进制时需要标注)
rb
wr
ab
View Code
文件句柄 = open('文件路径','读写模式')
打开文件的模式有:
r:只读,默认(文件不存在则报错)
w:只写(文件不存在则自动创建)
a:追加(文件不存在则自动创建)
'+'表示可同时读写文件
r+:读写(可读,可写,可追加),可读可写,不会清空文件
w+:写读,可使用read系列
a+:同a
"U"表示在读取时,可以将 \r \n \r\n自动转换成 \n (与 r 或 r+ 模式同使用)
rU
r+U
b:处理进制文件(如FTP发送上传镜像ISO文件,linux可忽略,WINDOWS处理二进制时需要标注)
rb
wr
ab
class TextIOWrapper(_TextIOBase): """ Character and line based layer over a BufferedIOBase object, buffer. encoding gives the name of the encoding that the stream will be decoded or encoded with. It defaults to locale.getpreferredencoding(False). errors determines the strictness of encoding and decoding (see help(codecs.Codec) or the documentation for codecs.register) and defaults to "strict". newline controls how line endings are handled. It can be None, '', '\n', '\r', and '\r\n'. It works as follows: * On input, if newline is None, universal newlines mode is enabled. Lines in the input can end in '\n', '\r', or '\r\n', and these are translated into '\n' before being returned to the caller. If it is '', universal newline mode is enabled, but line endings are returned to the caller untranslated. If it has any of the other legal values, input lines are only terminated by the given string, and the line ending is returned to the caller untranslated. * On output, if newline is None, any '\n' characters written are translated to the system default line separator, os.linesep. If newline is '' or '\n', no translation takes place. If newline is any of the other legal values, any '\n' characters written are translated to the given string. If line_buffering is True, a call to flush is implied when a call to write contains a newline character. """ def close(self, *args, **kwargs): # real signature unknown 关闭文件 pass def fileno(self, *args, **kwargs): # real signature unknown 文件描述符 pass def flush(self, *args, **kwargs): # real signature unknown 刷新文件内部缓冲区 pass def isatty(self, *args, **kwargs): # real signature unknown 判断文件是否是同意tty设备 pass def read(self, *args, **kwargs): # real signature unknown 读取指定字节数据 pass def readable(self, *args, **kwargs): # real signature unknown 是否可读 pass def readline(self, *args, **kwargs): # real signature unknown 仅读取一行数据 pass def seek(self, *args, **kwargs): # real signature unknown 指定文件中指针位置 pass def seekable(self, *args, **kwargs): # real signature unknown 指针是否可操作 pass def tell(self, *args, **kwargs): # real signature unknown 获取指针位置 pass def truncate(self, *args, **kwargs): # real signature unknown 截断数据,仅保留指定之前数据 pass def writable(self, *args, **kwargs): # real signature unknown 是否可写 pass def write(self, *args, **kwargs): # real signature unknown 写内容 pass def __getstate__(self, *args, **kwargs): # real signature unknown pass def __init__(self, *args, **kwargs): # real signature unknown pass @staticmethod # known case of __new__ def __new__(*args, **kwargs): # real signature unknown """ Create and return a new object. See help(type) for accurate signature. """ pass def __next__(self, *args, **kwargs): # real signature unknown """ Implement next(self). """ pass def __repr__(self, *args, **kwargs): # real signature unknown """ Return repr(self). """ pass buffer = property(lambda self: object(), lambda self, v: None, lambda self: None) # default closed = property(lambda self: object(), lambda self, v: None, lambda self: None) # default encoding = property(lambda self: object(), lambda self, v: None, lambda self: None) # default errors = property(lambda self: object(), lambda self, v: None, lambda self: None) # default line_buffering = property(lambda self: object(), lambda self, v: None, lambda self: None) # default name = property(lambda self: object(), lambda self, v: None, lambda self: None) # default newlines = property(lambda self: object(), lambda self, v: None, lambda self: None) # default _CHUNK_SIZE = property(lambda self: object(), lambda self, v: None, lambda self: None) # default _finalizing = property(lambda self: object(), lambda self, v: None, lambda self: None) # default Python 3.x
View Code
相关文章推荐
- Python第四章-字典
- python中的可变参数
- 关于的是python的爬虫
- Python数据类型之字典
- Python第三章-字符串
- 道格拉斯-普克 Douglas-Peuker(DP算法)-python实现
- pyenv的安装和使用
- 大量 python 爬虫源码分享--说说 python 爬虫这件小事
- Python数据类型之元祖
- 大量 python 爬虫源码分享--说说 python 爬虫这件小事
- Python面向对象的编程--Python学习笔记五
- Python数据类型之列表
- python -scikit
- 【LeetCode】Linked List Cycle 解题报告(Java & Python)
- python科学计算数据可视化模块-seaborn
- python基础语法
- python 学习笔记记录(一)
- PEP8 Python 编码规范
- 学习Python的三种境界
- Python yield and iterables