open函数,该函数用于文件处理

操作文件时,一般需要经历如下步骤:

  • 打开文件
  • 操作文件

一、打开文件

1

文件句柄 = open('文件路径', '模式')

打开文件时,需要指定文件路径和以何等方式打开文件,打开后,即可获取该文件句柄,日后通过此文件句柄对该文件操作。

打开文件的模式有:

  • r,只读模式(默认)。
  • w,只写模式。【不可读;不存在则创建;存在则删除内容;】
  • a,追加模式。【可读;   不存在则创建;存在则只追加内容;】

"+" 表示可以同时读写某个文件

  • r+,可读写文件。【可读;可写;可追加】
  • w+,写读
  • a+,同a

"U"表示在读取时,可以将 \r \n \r\n自动转换成 \n (与 r 或 r+ 模式同使用)

  • rU
  • r+U

"b"表示处理二进制文件(如:FTP发送上传ISO镜像文件,linux可忽略,windows处理二进制文件时需标注)

  • rb
  • wb
  • 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

最新文章

  1. Python黑帽编程1.3 Python运行时与包管理工具
  2. 学习zepto.js(对象方法)[5]
  3. urlencode
  4. JavaScript 回忆录
  5. js中eval详解,用Js的eval解析JSON中的注意点
  6. Winform禁止容器内控件获得焦点时改变容器显示范围坐标
  7. C# 配置文件读取与修改(转)
  8. 微信公众平台开发之基于百度 BAE3.0 的开发环境搭建(MyEclipse + SVN)
  9. [转载]PHP文件解压代码
  10. 安装 go 语言环境
  11. 微服务架构的基础框架选择:Spring Cloud还是Dubbo?
  12. 对于 Netty ByteBuf 的零拷贝(Zero Copy) 的理解
  13. Linux(二)—— Unix&Linux 的基本概念
  14. [UE4]AttachToComponent的AttachmentRule
  15. favicon.ico--网站标题小图片二三事
  16. css的再深入8(更新中···)
  17. npm 升降级
  18. 谈谈MySQL无法连接的原因和分析方法
  19. Failed to decode response: zlib_decode(): data error
  20. (笔记)Linux下如何查看高CPU占用率线程

热门文章

  1. OpenDayLight安装Features
  2. docker-compose部署微服务
  3. OUC_Summer Training_ DIV2_#7 718
  4. 使用UltraISO制作linux系统安装u盘启动盘
  5. Android View的加载流程
  6. Python Flask,cookie,session ,设置、获取、删除
  7. Redis4.0.11在linux上面安装时候编译的输出
  8. c语言数组类型默认值(c99)
  9. React Native的ListView的布局使用
  10. Java内部类(1):概述